/*
 * GainGUI.java
 *
 * Created on August 18, 2008, 10:25 AM
 */
package gain;

import java.awt.BorderLayout;
import javax.swing.text.html.*;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Vector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.TreeMap;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.event.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.metal.MetalFileChooserUI;
import javax.swing.table.DefaultTableModel;
import prefuse.util.ui.UILib;

/**
 *
 * @author  DTian
 */
public class GainGUI extends javax.swing.JFrame {

    /** Creates new form GainGUI */
    public GainGUI() {
        super("Genetic Association Interaction Network (0.0.1 alpha)");
        initComponents();
        initUserDefinedVar();
        setLocationRelativeTo(null);//center the window
        Thread myClock = new MyClock(jLabelClock);
        myClock.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPaneMain = new javax.swing.JTabbedPane();
        jPanelPreprocess = new javax.swing.JPanel();
        jPanelLoadData = new javax.swing.JPanel();
        jLabelBrowse = new javax.swing.JLabel();
        jButtonBrowseInFile = new javax.swing.JButton();
        jTextFieldLoadData = new javax.swing.JTextField();
        jCheckBoxShowFileInfo = new javax.swing.JCheckBox();
        jLabelNumberOfAttrsAndSample = new javax.swing.JLabel();
        jPanelOptionalAttribute = new javax.swing.JPanel();
        jLabelOptionAttribute = new javax.swing.JLabel();
        jButtonBrowseFilterFile = new javax.swing.JButton();
        jTextFieldOptionAttribute = new javax.swing.JTextField();
        jButtonApply = new javax.swing.JButton();
        jButtonRevert = new javax.swing.JButton();
        jTabbedPaneResultWindow = new javax.swing.JTabbedPane();
        jPanelExampleFileShow = new javax.swing.JPanel();
        jScrollPaneExampleFileShow = new javax.swing.JScrollPane();
        jTextAreaExampleFileShow = new javax.swing.JTextArea();
        jPanelCorrelationTable = new javax.swing.JPanel();
        jScrollPaneCorrelationTable = new javax.swing.JScrollPane();
        jTableCorrelations = new javax.swing.JTable();
        jButtonTableRemove = new javax.swing.JButton();
        jButtonSaveCorrelationsTable = new javax.swing.JButton();
        jPanelRemoveHistory = new javax.swing.JPanel();
        jScrollPaneRemoveHistory = new javax.swing.JScrollPane();
        jTextAreaRemoveHistory = new javax.swing.JTextArea();
        jPanelRemainAttrs = new javax.swing.JPanel();
        jScrollPaneRemainAttrs = new javax.swing.JScrollPane();
        jTableCorrelationsRemain = new javax.swing.JTable();
        jButtonSaveCorrelationsRemainData = new javax.swing.JButton();
        jButtonRemaingRemove = new javax.swing.JButton();
        jPanelCorrelation = new javax.swing.JPanel();
        jLabelSymmetirc = new javax.swing.JLabel();
        jTextFieldSymmetric = new javax.swing.JTextField();
        jLabelRunFilter = new javax.swing.JLabel();
        jButtonGetCorrelations = new javax.swing.JButton();
        jPanelInteraction = new javax.swing.JPanel();
        jPanelInteractionRun = new javax.swing.JPanel();
        jLabelRun = new javax.swing.JLabel();
        jButtonRunNetWork = new javax.swing.JButton();
        jLabelCutoff = new javax.swing.JLabel();
        jTextFieldCutoff = new javax.swing.JTextField();
        jPanelInteractionRefresh = new javax.swing.JPanel();
        jLabelInteractionGainRange = new javax.swing.JLabel();
        jTextFieldMinRange = new javax.swing.JTextField();
        jTextFieldMaxRange = new javax.swing.JTextField();
        jButtonRefresh = new javax.swing.JButton();
        jLabelInterGainRangeSplit = new javax.swing.JLabel();
        jTabbedPaneInteractionResult = new javax.swing.JTabbedPane();
        jPanelInteractionrResult = new javax.swing.JPanel();
        jScrollPaneInteractionResult = new javax.swing.JScrollPane();
        jTableInteractionGainResult = new javax.swing.JTable();
        jPanelNetworkDegrees = new javax.swing.JPanel();
        jScrollPaneNetworkDegrees = new javax.swing.JScrollPane();
        jTableNetworkDegrees = new javax.swing.JTable();
        jPanelInteractionSaveAs = new javax.swing.JPanel();
        jButtonSaveGain = new javax.swing.JButton();
        jLabelGain = new javax.swing.JLabel();
        jLabelSif = new javax.swing.JLabel();
        jLabelMatrix = new javax.swing.JLabel();
        jButtonSaveSif = new javax.swing.JButton();
        jButtonSaveMatrix = new javax.swing.JButton();
        jButtonSaveNetworkDegreesTable = new javax.swing.JButton();
        jLabelSaveTableAsTab = new javax.swing.JLabel();
        jPanelInteractionRefresh1 = new javax.swing.JPanel();
        jButtonShowNetwork = new javax.swing.JButton();
        jPanelRandomPermutation = new javax.swing.JPanel();
        jPanelPermutationControlPanel = new javax.swing.JPanel();
        jLabePermutelLoopCount = new javax.swing.JLabel();
        jTextFieldPermuteLoopCount = new javax.swing.JTextField();
        jButtonRunPermutation = new javax.swing.JButton();
        jLabelFalsePositiveRisk = new javax.swing.JLabel();
        jTextFieldFalsePositiveRisk = new javax.swing.JTextField();
        jSeparatorPermutationControlPanel = new javax.swing.JSeparator();
        jLabelInteractionGainCutoff = new javax.swing.JLabel();
        jTextFieldInteractionGainCutoff = new javax.swing.JTextField();
        jTabbedPanePermutation = new javax.swing.JTabbedPane();
        jPanelPermutationList = new javax.swing.JPanel();
        jScrollPanePermutationList = new javax.swing.JScrollPane();
        jTextAreaPermutationList = new javax.swing.JTextArea();
        jButtonSavePermutationList = new javax.swing.JButton();
        jPanelHelp = new javax.swing.JPanel();
        jLabelHelpTitle = new javax.swing.JLabel();
        jScrollPaneHelpContent = new javax.swing.JScrollPane();
        jEditorPaneHelpContent = new javax.swing.JEditorPane();
        jLabelGUIname = new javax.swing.JLabel();
        jPanelStatus = new javax.swing.JPanel();
        jTextFieldStatus = new javax.swing.JTextField();
        jProgressBarRun = new javax.swing.JProgressBar();
        jLabelClock = new javax.swing.JLabel();
        jMenuBarMain = new javax.swing.JMenuBar();
        jMenuFile = new javax.swing.JMenu();
        jMenuItemLoadData = new javax.swing.JMenuItem();
        jMenuItemLoadAttrNameList = new javax.swing.JMenuItem();
        jSeparatorFile = new javax.swing.JSeparator();
        jMenuItemSaveGain = new javax.swing.JMenuItem();
        jMenuItemSaveSif = new javax.swing.JMenuItem();
        jMenuItemSaveMatrix = new javax.swing.JMenuItem();
        jMenuItemSaveImage = new javax.swing.JMenuItem();
        jMenuItemSaveCorrelationd = new javax.swing.JMenuItem();
        jMenuItemSaveRemainingData = new javax.swing.JMenuItem();
        jMenuRun = new javax.swing.JMenu();
        jMenuItemApply = new javax.swing.JMenuItem();
        jMenuItemRevert = new javax.swing.JMenuItem();
        jSeparatorRun = new javax.swing.JSeparator();
        jMenuItemCalculate = new javax.swing.JMenuItem();
        jMenuItemRemoveFromCorrelatedTable = new javax.swing.JMenuItem();
        jMenuItemRemoveFromRemainTable = new javax.swing.JMenuItem();
        jSeparatorNetwork = new javax.swing.JSeparator();
        jMenuItemRunNetwork = new javax.swing.JMenuItem();
        jMenuItemShowNetwork = new javax.swing.JMenuItem();
        jMenuItemRefreshTable = new javax.swing.JMenuItem();
        jMenuExit = new javax.swing.JMenu();
        jMenuItemExit = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanelPreprocess.setEnabled(false);

        jPanelLoadData.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Load Data", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N
        jPanelLoadData.setPreferredSize(new java.awt.Dimension(735, 70));

        jLabelBrowse.setText("Choose the input file: ");

        jButtonBrowseInFile.setText("Browse");
        jButtonBrowseInFile.setMaximumSize(new java.awt.Dimension(85, 25));
        jButtonBrowseInFile.setMinimumSize(new java.awt.Dimension(85, 23));
        jButtonBrowseInFile.setPreferredSize(new java.awt.Dimension(85, 25));
        jButtonBrowseInFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBrowseInFileActionPerformed(evt);
            }
        });

        jTextFieldLoadData.setText("input file: ");
        jTextFieldLoadData.setAutoscrolls(false);

        jCheckBoxShowFileInfo.setText("Show File Infomation");
        jCheckBoxShowFileInfo.setToolTipText("If checked, will show the input file in the File Information Tab.\n( Do not check it if the file is very big. Otherwise it will take minutes to show, depend on the size of the file )");

        jLabelNumberOfAttrsAndSample.setText("Number of Attributes :    0     Number of Samples :    0");
        jLabelNumberOfAttrsAndSample.setEnabled(false);
        jLabelNumberOfAttrsAndSample.setMaximumSize(new java.awt.Dimension(691, 14));
        jLabelNumberOfAttrsAndSample.setMinimumSize(new java.awt.Dimension(691, 14));
        jLabelNumberOfAttrsAndSample.setPreferredSize(new java.awt.Dimension(691, 14));

        org.jdesktop.layout.GroupLayout jPanelLoadDataLayout = new org.jdesktop.layout.GroupLayout(jPanelLoadData);
        jPanelLoadData.setLayout(jPanelLoadDataLayout);
        jPanelLoadDataLayout.setHorizontalGroup(
            jPanelLoadDataLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelLoadDataLayout.createSequentialGroup()
                .add(21, 21, 21)
                .add(jPanelLoadDataLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabelNumberOfAttrsAndSample, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 643, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jPanelLoadDataLayout.createSequentialGroup()
                        .add(jLabelBrowse)
                        .add(43, 43, 43)
                        .add(jButtonBrowseInFile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(28, 28, 28)
                        .add(jTextFieldLoadData, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 181, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(54, 54, 54)
                        .add(jCheckBoxShowFileInfo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 158, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(57, 57, 57))
        );
        jPanelLoadDataLayout.setVerticalGroup(
            jPanelLoadDataLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelLoadDataLayout.createSequentialGroup()
                .add(jPanelLoadDataLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelBrowse)
                    .add(jCheckBoxShowFileInfo)
                    .add(jTextFieldLoadData, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButtonBrowseInFile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabelNumberOfAttrsAndSample, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelOptionalAttribute.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Attributes of Interest Filter (Optional).", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N
        jPanelOptionalAttribute.setPreferredSize(new java.awt.Dimension(735, 70));

        jLabelOptionAttribute.setText("Choose list of attributes file:");

        jButtonBrowseFilterFile.setText("Browse");
        jButtonBrowseFilterFile.setMaximumSize(new java.awt.Dimension(85, 25));
        jButtonBrowseFilterFile.setMinimumSize(new java.awt.Dimension(85, 23));
        jButtonBrowseFilterFile.setPreferredSize(new java.awt.Dimension(85, 25));
        jButtonBrowseFilterFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBrowseFilterFileActionPerformed(evt);
            }
        });

        jTextFieldOptionAttribute.setText("attribute file name:");
        jTextFieldOptionAttribute.setAutoscrolls(false);

        jButtonApply.setText("Apply");
        jButtonApply.setToolTipText("Remove the attributes which is not in the attributes file from the input file ");
        jButtonApply.setEnabled(false);
        jButtonApply.setMaximumSize(new java.awt.Dimension(85, 23));
        jButtonApply.setMinimumSize(new java.awt.Dimension(85, 23));
        jButtonApply.setPreferredSize(new java.awt.Dimension(85, 25));
        jButtonApply.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonApplyActionPerformed(evt);
            }
        });

        jButtonRevert.setText("Revert");
        jButtonRevert.setEnabled(false);
        jButtonRevert.setMaximumSize(new java.awt.Dimension(85, 23));
        jButtonRevert.setMinimumSize(new java.awt.Dimension(85, 23));
        jButtonRevert.setPreferredSize(new java.awt.Dimension(85, 25));
        jButtonRevert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRevertActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanelOptionalAttributeLayout = new org.jdesktop.layout.GroupLayout(jPanelOptionalAttribute);
        jPanelOptionalAttribute.setLayout(jPanelOptionalAttributeLayout);
        jPanelOptionalAttributeLayout.setHorizontalGroup(
            jPanelOptionalAttributeLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelOptionalAttributeLayout.createSequentialGroup()
                .add(18, 18, 18)
                .add(jLabelOptionAttribute)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jButtonBrowseFilterFile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(31, 31, 31)
                .add(jTextFieldOptionAttribute, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 177, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(56, 56, 56)
                .add(jButtonApply, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(32, 32, 32)
                .add(jButtonRevert, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(39, 39, 39))
        );
        jPanelOptionalAttributeLayout.setVerticalGroup(
            jPanelOptionalAttributeLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelOptionalAttributeLayout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jPanelOptionalAttributeLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelOptionAttribute)
                    .add(jButtonBrowseFilterFile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jTextFieldOptionAttribute, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButtonRevert, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButtonApply, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jTabbedPaneResultWindow.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Preview Data", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N
        jTabbedPaneResultWindow.setPreferredSize(new java.awt.Dimension(121, 209));

        jTextAreaExampleFileShow.setColumns(20);
        jTextAreaExampleFileShow.setEditable(false);
        jTextAreaExampleFileShow.setRows(5);
        jScrollPaneExampleFileShow.setViewportView(jTextAreaExampleFileShow);

        org.jdesktop.layout.GroupLayout jPanelExampleFileShowLayout = new org.jdesktop.layout.GroupLayout(jPanelExampleFileShow);
        jPanelExampleFileShow.setLayout(jPanelExampleFileShowLayout);
        jPanelExampleFileShowLayout.setHorizontalGroup(
            jPanelExampleFileShowLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPaneExampleFileShow, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 745, Short.MAX_VALUE)
        );
        jPanelExampleFileShowLayout.setVerticalGroup(
            jPanelExampleFileShowLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPaneExampleFileShow, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
        );

        jTabbedPaneResultWindow.addTab("File Information", jPanelExampleFileShow);

        jPanelCorrelationTable.setBackground(new java.awt.Color(153, 153, 153));

        jTableCorrelations.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTableCorrelations.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableCorrelationsMouseClicked(evt);
            }
        });
        jScrollPaneCorrelationTable.setViewportView(jTableCorrelations);

        jButtonTableRemove.setText("Remove");
        jButtonTableRemove.setToolTipText("remove the selected variable from the table");
        jButtonTableRemove.setEnabled(false);
        jButtonTableRemove.setPreferredSize(new java.awt.Dimension(110, 25));
        jButtonTableRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonTableRemoveActionPerformed(evt);
            }
        });

        jButtonSaveCorrelationsTable.setText("    SaveTable    ");
        jButtonSaveCorrelationsTable.setToolTipText("save the table as a tab delimited file");
        jButtonSaveCorrelationsTable.setPreferredSize(new java.awt.Dimension(110, 25));
        jButtonSaveCorrelationsTable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveCorrelationsTableActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanelCorrelationTableLayout = new org.jdesktop.layout.GroupLayout(jPanelCorrelationTable);
        jPanelCorrelationTable.setLayout(jPanelCorrelationTableLayout);
        jPanelCorrelationTableLayout.setHorizontalGroup(
            jPanelCorrelationTableLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelCorrelationTableLayout.createSequentialGroup()
                .add(147, 147, 147)
                .add(jButtonTableRemove, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 108, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(162, 162, 162)
                .add(jButtonSaveCorrelationsTable, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(218, Short.MAX_VALUE))
            .add(jScrollPaneCorrelationTable, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 745, Short.MAX_VALUE)
        );
        jPanelCorrelationTableLayout.setVerticalGroup(
            jPanelCorrelationTableLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelCorrelationTableLayout.createSequentialGroup()
                .add(jScrollPaneCorrelationTable, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 207, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jPanelCorrelationTableLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonSaveCorrelationsTable, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButtonTableRemove, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(14, 14, 14))
        );

        jTabbedPaneResultWindow.addTab("Show Correlated", jPanelCorrelationTable);

        jTextAreaRemoveHistory.setColumns(20);
        jTextAreaRemoveHistory.setEditable(false);
        jTextAreaRemoveHistory.setRows(5);
        jScrollPaneRemoveHistory.setViewportView(jTextAreaRemoveHistory);

        org.jdesktop.layout.GroupLayout jPanelRemoveHistoryLayout = new org.jdesktop.layout.GroupLayout(jPanelRemoveHistory);
        jPanelRemoveHistory.setLayout(jPanelRemoveHistoryLayout);
        jPanelRemoveHistoryLayout.setHorizontalGroup(
            jPanelRemoveHistoryLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPaneRemoveHistory, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 745, Short.MAX_VALUE)
        );
        jPanelRemoveHistoryLayout.setVerticalGroup(
            jPanelRemoveHistoryLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPaneRemoveHistory, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
        );

        jTabbedPaneResultWindow.addTab("Remove History", jPanelRemoveHistory);

        jTableCorrelationsRemain.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTableCorrelationsRemain.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableCorrelationsRemainMouseClicked(evt);
            }
        });
        jScrollPaneRemainAttrs.setViewportView(jTableCorrelationsRemain);

        jButtonSaveCorrelationsRemainData.setText("Save Remaining Data");
        jButtonSaveCorrelationsRemainData.setToolTipText("save the input file with only the variables in the table as a new tab delimited file");
        jButtonSaveCorrelationsRemainData.setPreferredSize(new java.awt.Dimension(110, 25));
        jButtonSaveCorrelationsRemainData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveCorrelationsRemainDataActionPerformed(evt);
            }
        });

        jButtonRemaingRemove.setText("Remove Selected");
        jButtonRemaingRemove.setToolTipText("remove the selected line from the table");
        jButtonRemaingRemove.setPreferredSize(new java.awt.Dimension(110, 25));
        jButtonRemaingRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRemaingRemoveActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanelRemainAttrsLayout = new org.jdesktop.layout.GroupLayout(jPanelRemainAttrs);
        jPanelRemainAttrs.setLayout(jPanelRemainAttrsLayout);
        jPanelRemainAttrsLayout.setHorizontalGroup(
            jPanelRemainAttrsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPaneRemainAttrs, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 745, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelRemainAttrsLayout.createSequentialGroup()
                .addContainerGap(128, Short.MAX_VALUE)
                .add(jButtonRemaingRemove, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 151, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(205, 205, 205)
                .add(jButtonSaveCorrelationsRemainData, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 150, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(111, 111, 111))
        );
        jPanelRemainAttrsLayout.setVerticalGroup(
            jPanelRemainAttrsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelRemainAttrsLayout.createSequentialGroup()
                .add(jScrollPaneRemainAttrs, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 202, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jPanelRemainAttrsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonRemaingRemove, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButtonSaveCorrelationsRemainData, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jTabbedPaneResultWindow.addTab("Show Remaining", jPanelRemainAttrs);

        jPanelCorrelation.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Pair-wise Correlations", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N
        jPanelCorrelation.setPreferredSize(new java.awt.Dimension(735, 70));

        jLabelSymmetirc.setText("Correlation Threshold:");

        jTextFieldSymmetric.setText("0.8");

        jLabelRunFilter.setText("Click to run: ");

        jButtonGetCorrelations.setText("Calculate");
        jButtonGetCorrelations.setToolTipText("Calculate the Correlations with the value is grreat than the Threshold");
        jButtonGetCorrelations.setEnabled(false);
        jButtonGetCorrelations.setPreferredSize(new java.awt.Dimension(110, 25));
        jButtonGetCorrelations.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGetCorrelationsActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanelCorrelationLayout = new org.jdesktop.layout.GroupLayout(jPanelCorrelation);
        jPanelCorrelation.setLayout(jPanelCorrelationLayout);
        jPanelCorrelationLayout.setHorizontalGroup(
            jPanelCorrelationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelCorrelationLayout.createSequentialGroup()
                .add(37, 37, 37)
                .add(jLabelSymmetirc)
                .add(50, 50, 50)
                .add(jTextFieldSymmetric, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 68, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 157, Short.MAX_VALUE)
                .add(jLabelRunFilter)
                .add(65, 65, 65)
                .add(jButtonGetCorrelations, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(96, 96, 96))
        );
        jPanelCorrelationLayout.setVerticalGroup(
            jPanelCorrelationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelCorrelationLayout.createSequentialGroup()
                .add(jPanelCorrelationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelSymmetirc)
                    .add(jTextFieldSymmetric, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButtonGetCorrelations, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabelRunFilter))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout jPanelPreprocessLayout = new org.jdesktop.layout.GroupLayout(jPanelPreprocess);
        jPanelPreprocess.setLayout(jPanelPreprocessLayout);
        jPanelPreprocessLayout.setHorizontalGroup(
            jPanelPreprocessLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelPreprocessLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelPreprocessLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelLoadData, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE)
                    .add(jTabbedPaneResultWindow, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE)
                    .add(jPanelCorrelation, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE)
                    .add(jPanelOptionalAttribute, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelPreprocessLayout.setVerticalGroup(
            jPanelPreprocessLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelPreprocessLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelLoadData, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanelOptionalAttribute, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanelCorrelation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jTabbedPaneResultWindow, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 323, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPaneMain.addTab("Preprocess", jPanelPreprocess);

        jPanelInteractionRun.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Interaction Calculation", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N
        jPanelInteractionRun.setPreferredSize(new java.awt.Dimension(100, 70));

        jLabelRun.setText("Calculate :");

        jButtonRunNetWork.setText("Run");
        jButtonRunNetWork.setToolTipText("Calculate the interaction table with the interaction gain is great than the low bound");
        jButtonRunNetWork.setEnabled(false);
        jButtonRunNetWork.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRunNetWorkActionPerformed(evt);
            }
        });

        jLabelCutoff.setText("Interaction Lower Bound:");

        jTextFieldCutoff.setText("0.05");

        org.jdesktop.layout.GroupLayout jPanelInteractionRunLayout = new org.jdesktop.layout.GroupLayout(jPanelInteractionRun);
        jPanelInteractionRun.setLayout(jPanelInteractionRunLayout);
        jPanelInteractionRunLayout.setHorizontalGroup(
            jPanelInteractionRunLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelInteractionRunLayout.createSequentialGroup()
                .add(49, 49, 49)
                .add(jLabelCutoff)
                .add(43, 43, 43)
                .add(jTextFieldCutoff, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 54, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 141, Short.MAX_VALUE)
                .add(jLabelRun)
                .add(26, 26, 26)
                .add(jButtonRunNetWork, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(162, 162, 162))
        );
        jPanelInteractionRunLayout.setVerticalGroup(
            jPanelInteractionRunLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelInteractionRunLayout.createSequentialGroup()
                .add(jPanelInteractionRunLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldCutoff, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabelCutoff)
                    .add(jButtonRunNetWork)
                    .add(jLabelRun))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jPanelInteractionRefresh.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Displayed in Table", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N
        jPanelInteractionRefresh.setPreferredSize(new java.awt.Dimension(100, 70));

        jLabelInteractionGainRange.setText("Interaction Gain Range: ");

        jTextFieldMinRange.setPreferredSize(new java.awt.Dimension(50, 20));
        jTextFieldMinRange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldMinRangeActionPerformed(evt);
            }
        });

        jTextFieldMaxRange.setPreferredSize(new java.awt.Dimension(50, 20));
        jTextFieldMaxRange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldMaxRangeActionPerformed(evt);
            }
        });

        jButtonRefresh.setText("Refresh Table");
        jButtonRefresh.setToolTipText("Refresh interaction table based on the new interaction gain range ");
        jButtonRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRefreshActionPerformed(evt);
            }
        });

        jLabelInterGainRangeSplit.setText(":");

        org.jdesktop.layout.GroupLayout jPanelInteractionRefreshLayout = new org.jdesktop.layout.GroupLayout(jPanelInteractionRefresh);
        jPanelInteractionRefresh.setLayout(jPanelInteractionRefreshLayout);
        jPanelInteractionRefreshLayout.setHorizontalGroup(
            jPanelInteractionRefreshLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelInteractionRefreshLayout.createSequentialGroup()
                .add(101, 101, 101)
                .add(jLabelInteractionGainRange)
                .add(18, 18, 18)
                .add(jTextFieldMinRange, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(12, 12, 12)
                .add(jLabelInterGainRangeSplit)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jTextFieldMaxRange, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(128, 128, 128)
                .add(jButtonRefresh)
                .addContainerGap(160, Short.MAX_VALUE))
        );
        jPanelInteractionRefreshLayout.setVerticalGroup(
            jPanelInteractionRefreshLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelInteractionRefreshLayout.createSequentialGroup()
                .add(jPanelInteractionRefreshLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldMinRange, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jTextFieldMaxRange, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabelInterGainRangeSplit)
                    .add(jLabelInteractionGainRange)
                    .add(jButtonRefresh))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jPanelInteractionrResult.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jTableInteractionGainResult.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPaneInteractionResult.setViewportView(jTableInteractionGainResult);

        org.jdesktop.layout.GroupLayout jPanelInteractionrResultLayout = new org.jdesktop.layout.GroupLayout(jPanelInteractionrResult);
        jPanelInteractionrResult.setLayout(jPanelInteractionrResultLayout);
        jPanelInteractionrResultLayout.setHorizontalGroup(
            jPanelInteractionrResultLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPaneInteractionResult, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 745, Short.MAX_VALUE)
        );
        jPanelInteractionrResultLayout.setVerticalGroup(
            jPanelInteractionrResultLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPaneInteractionResult, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
        );

        jTabbedPaneInteractionResult.addTab("Interaction Table", jPanelInteractionrResult);

        jTableNetworkDegrees.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPaneNetworkDegrees.setViewportView(jTableNetworkDegrees);

        org.jdesktop.layout.GroupLayout jPanelNetworkDegreesLayout = new org.jdesktop.layout.GroupLayout(jPanelNetworkDegrees);
        jPanelNetworkDegrees.setLayout(jPanelNetworkDegreesLayout);
        jPanelNetworkDegreesLayout.setHorizontalGroup(
            jPanelNetworkDegreesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelNetworkDegreesLayout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPaneNetworkDegrees, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 741, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelNetworkDegreesLayout.setVerticalGroup(
            jPanelNetworkDegreesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelNetworkDegreesLayout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPaneNetworkDegrees, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPaneInteractionResult.addTab("Network Degrees", jPanelNetworkDegrees);

        jButtonSaveGain.setText("Save Table as tab");
        jButtonSaveGain.setEnabled(false);
        jButtonSaveGain.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveGainActionPerformed(evt);
            }
        });

        jLabelGain.setText("Interaction Table :");

        jLabelSif.setText("Cytoscape Format :");

        jLabelMatrix.setText("Interaction matrix :");

        jButtonSaveSif.setText("Save  As  Sif");
        jButtonSaveSif.setEnabled(false);
        jButtonSaveSif.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveSifActionPerformed(evt);
            }
        });

        jButtonSaveMatrix.setText("Save Matrix as tab");
        jButtonSaveMatrix.setEnabled(false);
        jButtonSaveMatrix.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveMatrixActionPerformed(evt);
            }
        });

        jButtonSaveNetworkDegreesTable.setText("Save Table as tab");
        jButtonSaveNetworkDegreesTable.setEnabled(false);
        jButtonSaveNetworkDegreesTable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveNetworkDegreesTableActionPerformed(evt);
            }
        });

        jLabelSaveTableAsTab.setText("Degree Table :");

        org.jdesktop.layout.GroupLayout jPanelInteractionSaveAsLayout = new org.jdesktop.layout.GroupLayout(jPanelInteractionSaveAs);
        jPanelInteractionSaveAs.setLayout(jPanelInteractionSaveAsLayout);
        jPanelInteractionSaveAsLayout.setHorizontalGroup(
            jPanelInteractionSaveAsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelInteractionSaveAsLayout.createSequentialGroup()
                .add(79, 79, 79)
                .add(jPanelInteractionSaveAsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabelSif)
                    .add(jLabelMatrix)
                    .add(jLabelGain)
                    .add(jLabelSaveTableAsTab))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 262, Short.MAX_VALUE)
                .add(jPanelInteractionSaveAsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jButtonSaveNetworkDegreesTable, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jButtonSaveGain, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jButtonSaveSif, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jButtonSaveMatrix, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .add(202, 202, 202))
        );
        jPanelInteractionSaveAsLayout.setVerticalGroup(
            jPanelInteractionSaveAsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelInteractionSaveAsLayout.createSequentialGroup()
                .addContainerGap(74, Short.MAX_VALUE)
                .add(jPanelInteractionSaveAsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabelGain)
                    .add(jButtonSaveGain))
                .add(23, 23, 23)
                .add(jPanelInteractionSaveAsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabelSif)
                    .add(jButtonSaveSif))
                .add(27, 27, 27)
                .add(jPanelInteractionSaveAsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelMatrix)
                    .add(jButtonSaveMatrix))
                .add(28, 28, 28)
                .add(jPanelInteractionSaveAsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jButtonSaveNetworkDegreesTable)
                    .add(jLabelSaveTableAsTab))
                .add(70, 70, 70))
        );

        jTabbedPaneInteractionResult.addTab("Export Results", jPanelInteractionSaveAs);

        jPanelInteractionRefresh1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Visualize", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N
        jPanelInteractionRefresh1.setPreferredSize(new java.awt.Dimension(100, 70));

        jButtonShowNetwork.setText("Visualize Network");
        jButtonShowNetwork.setToolTipText("Show the network based on the variables selected from interaction table");
        jButtonShowNetwork.setEnabled(false);
        jButtonShowNetwork.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonShowNetworkActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanelInteractionRefresh1Layout = new org.jdesktop.layout.GroupLayout(jPanelInteractionRefresh1);
        jPanelInteractionRefresh1.setLayout(jPanelInteractionRefresh1Layout);
        jPanelInteractionRefresh1Layout.setHorizontalGroup(
            jPanelInteractionRefresh1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelInteractionRefresh1Layout.createSequentialGroup()
                .add(301, 301, 301)
                .add(jButtonShowNetwork)
                .addContainerGap(334, Short.MAX_VALUE))
        );
        jPanelInteractionRefresh1Layout.setVerticalGroup(
            jPanelInteractionRefresh1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelInteractionRefresh1Layout.createSequentialGroup()
                .add(jButtonShowNetwork)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout jPanelInteractionLayout = new org.jdesktop.layout.GroupLayout(jPanelInteraction);
        jPanelInteraction.setLayout(jPanelInteractionLayout);
        jPanelInteractionLayout.setHorizontalGroup(
            jPanelInteractionLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelInteractionLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelInteractionLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jTabbedPaneInteractionResult, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelInteractionRun, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE)
                    .add(jPanelInteractionRefresh, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE)
                    .add(jPanelInteractionRefresh1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelInteractionLayout.setVerticalGroup(
            jPanelInteractionLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelInteractionLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelInteractionRun, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanelInteractionRefresh, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 13, Short.MAX_VALUE)
                .add(jPanelInteractionRefresh1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jTabbedPaneInteractionResult, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 342, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPaneMain.addTab("Interaction Analysis", jPanelInteraction);

        jLabePermutelLoopCount.setText("Number of Pairs :");

        jTextFieldPermuteLoopCount.setText("500");

        jButtonRunPermutation.setText("Run");
        jButtonRunPermutation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRunPermutationActionPerformed(evt);
            }
        });

        jLabelFalsePositiveRisk.setText("False Positive Risk: ");

        jTextFieldFalsePositiveRisk.setText("0.05");

        jLabelInteractionGainCutoff.setText("Interaction Gain Cutoff: ");

        jTextFieldInteractionGainCutoff.setEditable(false);

        org.jdesktop.layout.GroupLayout jPanelPermutationControlPanelLayout = new org.jdesktop.layout.GroupLayout(jPanelPermutationControlPanel);
        jPanelPermutationControlPanel.setLayout(jPanelPermutationControlPanelLayout);
        jPanelPermutationControlPanelLayout.setHorizontalGroup(
            jPanelPermutationControlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelPermutationControlPanelLayout.createSequentialGroup()
                .add(jPanelPermutationControlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanelPermutationControlPanelLayout.createSequentialGroup()
                        .add(55, 55, 55)
                        .add(jPanelPermutationControlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparatorPermutationControlPanel)
                            .add(jPanelPermutationControlPanelLayout.createSequentialGroup()
                                .add(jLabePermutelLoopCount)
                                .add(37, 37, 37)
                                .add(jTextFieldPermuteLoopCount, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 65, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(45, 45, 45)
                                .add(jLabelFalsePositiveRisk)
                                .add(37, 37, 37)
                                .add(jTextFieldFalsePositiveRisk, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(55, 55, 55)
                                .add(jButtonRunPermutation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 94, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(jPanelPermutationControlPanelLayout.createSequentialGroup()
                        .add(169, 169, 169)
                        .add(jLabelInteractionGainCutoff)
                        .add(29, 29, 29)
                        .add(jTextFieldInteractionGainCutoff, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 205, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(66, Short.MAX_VALUE))
        );
        jPanelPermutationControlPanelLayout.setVerticalGroup(
            jPanelPermutationControlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelPermutationControlPanelLayout.createSequentialGroup()
                .add(26, 26, 26)
                .add(jPanelPermutationControlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabePermutelLoopCount)
                    .add(jTextFieldPermuteLoopCount, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabelFalsePositiveRisk)
                    .add(jTextFieldFalsePositiveRisk, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButtonRunPermutation))
                .add(18, 18, 18)
                .add(jSeparatorPermutationControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanelPermutationControlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldInteractionGainCutoff, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabelInteractionGainCutoff))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTextAreaPermutationList.setColumns(20);
        jTextAreaPermutationList.setEditable(false);
        jTextAreaPermutationList.setRows(5);
        jTextAreaPermutationList.setEnabled(false);
        jScrollPanePermutationList.setViewportView(jTextAreaPermutationList);

        jButtonSavePermutationList.setText("Save List");
        jButtonSavePermutationList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSavePermutationListActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanelPermutationListLayout = new org.jdesktop.layout.GroupLayout(jPanelPermutationList);
        jPanelPermutationList.setLayout(jPanelPermutationListLayout);
        jPanelPermutationListLayout.setHorizontalGroup(
            jPanelPermutationListLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelPermutationListLayout.createSequentialGroup()
                .add(343, 343, 343)
                .add(jButtonSavePermutationList)
                .addContainerGap(343, Short.MAX_VALUE))
            .add(jPanelPermutationListLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanelPermutationListLayout.createSequentialGroup()
                    .add(42, 42, 42)
                    .add(jScrollPanePermutationList, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 691, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(28, Short.MAX_VALUE)))
        );
        jPanelPermutationListLayout.setVerticalGroup(
            jPanelPermutationListLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelPermutationListLayout.createSequentialGroup()
                .addContainerGap(355, Short.MAX_VALUE)
                .add(jButtonSavePermutationList)
                .add(31, 31, 31))
            .add(jPanelPermutationListLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanelPermutationListLayout.createSequentialGroup()
                    .add(25, 25, 25)
                    .add(jScrollPanePermutationList, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 310, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(74, Short.MAX_VALUE)))
        );

        jTabbedPanePermutation.addTab("Permutation Result", jPanelPermutationList);

        org.jdesktop.layout.GroupLayout jPanelRandomPermutationLayout = new org.jdesktop.layout.GroupLayout(jPanelRandomPermutation);
        jPanelRandomPermutation.setLayout(jPanelRandomPermutationLayout);
        jPanelRandomPermutationLayout.setHorizontalGroup(
            jPanelRandomPermutationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelRandomPermutationLayout.createSequentialGroup()
                .add(jPanelRandomPermutationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanelRandomPermutationLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(jTabbedPanePermutation, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE))
                    .add(jPanelRandomPermutationLayout.createSequentialGroup()
                        .add(44, 44, 44)
                        .add(jPanelPermutationControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanelRandomPermutationLayout.setVerticalGroup(
            jPanelRandomPermutationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelRandomPermutationLayout.createSequentialGroup()
                .add(23, 23, 23)
                .add(jPanelPermutationControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 20, Short.MAX_VALUE)
                .add(jTabbedPanePermutation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 437, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPaneMain.addTab(" Permutation Analysis", jPanelRandomPermutation);

        jLabelHelpTitle.setBackground(new java.awt.Color(153, 153, 153));
        jLabelHelpTitle.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabelHelpTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelHelpTitle.setText("<html><u>Genetic Association Interaction Network (GAIN)</u></html>"); // NOI18N

        jScrollPaneHelpContent.setBorder(null);

        jEditorPaneHelpContent.setBackground(new java.awt.Color(236, 233, 216));
        jEditorPaneHelpContent.setBorder(null);
        jEditorPaneHelpContent.setEditable(false);
        jEditorPaneHelpContent.setEditorKit(new HTMLEditorKit());
        jEditorPaneHelpContent.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jEditorPaneHelpContent.setText("<html><p>The open-source GAIN software package was developed by <a href=\"mailto:brett.mckinney@gmail.com\" >Dr. Brett A. McKinney</a>. GAIN is an information theory based method for characterizing and visualizing interactions between DNA sequence variants that influence the phenotype in association studies.  For additional information please visit the <a href=\"http://sites.google.com/site/mckinneylab/software/Information-Theoretic-Genetic-Analysis\" target=\"_blank\">GAIN Software home page </a>. </p> <br> <p>GAIN is an open source software released under the GNU General Public License, Version 2.</p>  <p>This program is a free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but <b>WITHOUT ANY WARRANTY</b>; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the <a href=\"http://www.gnu.org/licenses/old-licenses/gpl-2.0.html\">GNU General Public License</a> for more details.</p><br> <p> We would also like to acknowledge the <a href=\"http://prefuse.org/\"> prefuse visualization toolkit</a>.</p> </html>");
        jEditorPaneHelpContent.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jEditorPaneHelpContent.setEnabled(false);
        jEditorPaneHelpContent.setOpaque(false);
        jScrollPaneHelpContent.setViewportView(jEditorPaneHelpContent);

        org.jdesktop.layout.GroupLayout jPanelHelpLayout = new org.jdesktop.layout.GroupLayout(jPanelHelp);
        jPanelHelp.setLayout(jPanelHelpLayout);
        jPanelHelpLayout.setHorizontalGroup(
            jPanelHelpLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelHelpLayout.createSequentialGroup()
                .add(190, 190, 190)
                .add(jLabelHelpTitle, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 393, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(203, Short.MAX_VALUE))
            .add(jPanelHelpLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanelHelpLayout.createSequentialGroup()
                    .add(99, 99, 99)
                    .add(jScrollPaneHelpContent, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 601, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(86, Short.MAX_VALUE)))
        );
        jPanelHelpLayout.setVerticalGroup(
            jPanelHelpLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelHelpLayout.createSequentialGroup()
                .add(53, 53, 53)
                .add(jLabelHelpTitle)
                .addContainerGap(529, Short.MAX_VALUE))
            .add(jPanelHelpLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanelHelpLayout.createSequentialGroup()
                    .add(126, 126, 126)
                    .add(jScrollPaneHelpContent, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 388, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(90, Short.MAX_VALUE)))
        );

        jTabbedPaneMain.addTab("Help", jPanelHelp);

        jLabelGUIname.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabelGUIname.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelGUIname.setText("Genetic Association Interaction Network (0.0.1 alpha)");

        jPanelStatus.setPreferredSize(new java.awt.Dimension(780, 65));

        jTextFieldStatus.setText("status:");
        jTextFieldStatus.setPreferredSize(new java.awt.Dimension(600, 22));

        jProgressBarRun.setMaximumSize(new java.awt.Dimension(20, 18));
        jProgressBarRun.setMinimumSize(new java.awt.Dimension(20, 18));
        jProgressBarRun.setPreferredSize(new java.awt.Dimension(780, 20));

        jLabelClock.setEnabled(false);
        jLabelClock.setPreferredSize(new java.awt.Dimension(180, 22));

        org.jdesktop.layout.GroupLayout jPanelStatusLayout = new org.jdesktop.layout.GroupLayout(jPanelStatus);
        jPanelStatus.setLayout(jPanelStatusLayout);
        jPanelStatusLayout.setHorizontalGroup(
            jPanelStatusLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelStatusLayout.createSequentialGroup()
                .add(jPanelStatusLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanelStatusLayout.createSequentialGroup()
                        .add(jTextFieldStatus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 600, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabelClock, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jProgressBarRun, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 801, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelStatusLayout.setVerticalGroup(
            jPanelStatusLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelStatusLayout.createSequentialGroup()
                .add(12, 12, 12)
                .add(jProgressBarRun, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 8, Short.MAX_VALUE)
                .add(jPanelStatusLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldStatus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabelClock, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );

        jMenuFile.setText("File");
        jMenuFile.setMnemonic('F');

        jMenuItemLoadData.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemLoadData.setMnemonic('B');
        jMenuItemLoadData.setText("Browse input file...");
        jMenuItemLoadData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemLoadDataActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemLoadData);

        jMenuItemLoadAttrNameList.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemLoadAttrNameList.setMnemonic('a');
        jMenuItemLoadAttrNameList.setText("Browse attributes list file...");
        jMenuItemLoadAttrNameList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemLoadAttrNameListActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemLoadAttrNameList);
        jMenuFile.add(jSeparatorFile);

        jMenuItemSaveGain.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemSaveGain.setMnemonic('g');
        jMenuItemSaveGain.setText("Save Gain file");
        jMenuItemSaveGain.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSaveGainActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemSaveGain);

        jMenuItemSaveSif.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemSaveSif.setMnemonic('s');
        jMenuItemSaveSif.setText("Save Sif file");
        jMenuItemSaveSif.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSaveSifActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemSaveSif);

        jMenuItemSaveMatrix.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemSaveMatrix.setMnemonic('M');
        jMenuItemSaveMatrix.setText("Save Matrix file");
        jMenuItemSaveMatrix.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSaveMatrixActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemSaveMatrix);

        jMenuItemSaveImage.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemSaveImage.setMnemonic('I');
        jMenuItemSaveImage.setText("Save Image file");
        jMenuFile.add(jMenuItemSaveImage);

        jMenuItemSaveCorrelationd.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemSaveCorrelationd.setMnemonic('T');
        jMenuItemSaveCorrelationd.setText("Save Correlation Table");
        jMenuFile.add(jMenuItemSaveCorrelationd);

        jMenuItemSaveRemainingData.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemSaveRemainingData.setMnemonic('D');
        jMenuItemSaveRemainingData.setText("Save Remaining Data");
        jMenuItemSaveRemainingData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSaveRemainingDataActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemSaveRemainingData);

        jMenuBarMain.add(jMenuFile);

        jMenuRun.setText("Run");

        jMenuItemApply.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemApply.setMnemonic('p');
        jMenuItemApply.setText("Apply");
        jMenuItemApply.setEnabled(false);
        jMenuItemApply.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemApplyActionPerformed(evt);
            }
        });
        jMenuRun.add(jMenuItemApply);

        jMenuItemRevert.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemRevert.setMnemonic('v');
        jMenuItemRevert.setText("Revert");
        jMenuItemRevert.setEnabled(false);
        jMenuItemRevert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemRevertActionPerformed(evt);
            }
        });
        jMenuRun.add(jMenuItemRevert);
        jMenuRun.add(jSeparatorRun);

        jMenuItemCalculate.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemCalculate.setMnemonic('C');
        jMenuItemCalculate.setText("Calculate Correlations");
        jMenuItemCalculate.setEnabled(false);
        jMenuItemCalculate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemCalculateActionPerformed(evt);
            }
        });
        jMenuRun.add(jMenuItemCalculate);

        jMenuItemRemoveFromCorrelatedTable.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemRemoveFromCorrelatedTable.setMnemonic('o');
        jMenuItemRemoveFromCorrelatedTable.setText("Remove from correlations table");
        jMenuItemRemoveFromCorrelatedTable.setEnabled(false);
        jMenuRun.add(jMenuItemRemoveFromCorrelatedTable);

        jMenuItemRemoveFromRemainTable.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemRemoveFromRemainTable.setMnemonic('e');
        jMenuItemRemoveFromRemainTable.setText("Remove from remaining table");
        jMenuItemRemoveFromRemainTable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemRemoveFromRemainTableActionPerformed(evt);
            }
        });
        jMenuRun.add(jMenuItemRemoveFromRemainTable);
        jMenuRun.add(jSeparatorNetwork);

        jMenuItemRunNetwork.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemRunNetwork.setMnemonic('R');
        jMenuItemRunNetwork.setText("Run Network");
        jMenuItemRunNetwork.setEnabled(false);
        jMenuItemRunNetwork.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemRunNetworkActionPerformed(evt);
            }
        });
        jMenuRun.add(jMenuItemRunNetwork);

        jMenuItemShowNetwork.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemShowNetwork.setMnemonic('N');
        jMenuItemShowNetwork.setText("Show Network");
        jMenuItemShowNetwork.setEnabled(false);
        jMenuItemShowNetwork.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemShowNetworkActionPerformed(evt);
            }
        });
        jMenuRun.add(jMenuItemShowNetwork);

        jMenuItemRefreshTable.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemRefreshTable.setMnemonic('f');
        jMenuItemRefreshTable.setText("Refresh Interactiontable");
        jMenuItemRefreshTable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemRefreshTableActionPerformed(evt);
            }
        });
        jMenuRun.add(jMenuItemRefreshTable);

        jMenuBarMain.add(jMenuRun);

        jMenuExit.setText("Exit");

        jMenuItemExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemExit.setMnemonic('x');
        jMenuItemExit.setText("Exit");
        jMenuItemExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemExitActionPerformed(evt);
            }
        });
        jMenuExit.add(jMenuItemExit);

        jMenuBarMain.add(jMenuExit);

        setJMenuBar(jMenuBarMain);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelStatus, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 811, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPaneMain, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 791, Short.MAX_VALUE)
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(137, Short.MAX_VALUE)
                .add(jLabelGUIname, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 540, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(134, 134, 134))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(19, 19, 19)
                .add(jLabelGUIname, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 37, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jTabbedPaneMain, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 632, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanelStatus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItemExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemExitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuItemExitActionPerformed

    private void jMenuItemLoadDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemLoadDataActionPerformed
        jButtonBrowseInFileActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemLoadDataActionPerformed

    private void jMenuItemLoadAttrNameListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemLoadAttrNameListActionPerformed
        jButtonBrowseFilterFileActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemLoadAttrNameListActionPerformed

    private void jMenuItemSaveGainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSaveGainActionPerformed
        jButtonSaveGainActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemSaveGainActionPerformed

    private void jMenuItemSaveSifActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSaveSifActionPerformed
        jButtonSaveSifActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemSaveSifActionPerformed

    private void jMenuItemSaveMatrixActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSaveMatrixActionPerformed
        jButtonSaveMatrixActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemSaveMatrixActionPerformed

    private void jMenuItemApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemApplyActionPerformed
        jButtonApplyActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemApplyActionPerformed

    private void jMenuItemRevertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemRevertActionPerformed
        jButtonRevertActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemRevertActionPerformed

    private void jMenuItemCalculateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCalculateActionPerformed
        jButtonGetCorrelationsActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemCalculateActionPerformed

    private void jMenuItemRunNetworkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemRunNetworkActionPerformed
        jButtonRunNetWorkActionPerformed(evt);
}//GEN-LAST:event_jMenuItemRunNetworkActionPerformed

    private void jMenuItemShowNetworkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemShowNetworkActionPerformed
        jButtonShowNetworkActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemShowNetworkActionPerformed

    private void jMenuItemRemoveFromRemainTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemRemoveFromRemainTableActionPerformed
        jButtonRemaingRemoveActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemRemoveFromRemainTableActionPerformed

    private void jMenuItemRefreshTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemRefreshTableActionPerformed
        jButtonRefreshActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemRefreshTableActionPerformed

    private void jMenuItemSaveRemainingDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSaveRemainingDataActionPerformed
        jButtonSaveCorrelationsRemainDataActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemSaveRemainingDataActionPerformed

    private void jButtonSavePermutationListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSavePermutationListActionPerformed
        setMouseBusy();
        jTextFieldStatus.setText("permutation List is saving...");
        //get the file
        int fileOpenReturnValue = jFileChooserMain.showSaveDialog(new java.awt.Component() {
        });

        if (fileOpenReturnValue == JFileChooser.APPROVE_OPTION) {
            String saveFile = jFileChooserMain.getSelectedFile().getAbsolutePath();
            //get the date need to be wroten
            try {
                FileWriter fw = new FileWriter(saveFile);
                BufferedWriter writer = new BufferedWriter(fw);

                writer.write(jTextAreaPermutationList.getText());

                writer.close();
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e.toString());
            }

            setMouseDefault();
            jTextFieldStatus.setText("permutation List is saved.");
        } else if (fileOpenReturnValue == JFileChooser.CANCEL_OPTION) {
            setMouseDefault();
        }
}//GEN-LAST:event_jButtonSavePermutationListActionPerformed

    private void jButtonRunPermutationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRunPermutationActionPerformed
        setMouseBusy();
        jButtonRunNetWork.setEnabled(false);
        jButtonGetCorrelations.setEnabled(false);

        //local variables
        int loop = 0;
        int rand = 0;
        int stopLoop = Integer.parseInt(jTextFieldPermuteLoopCount.getText());
        double[] scoreArray = new double[stopLoop];
        String snp1 = "";
        String snp2 = "";
        ArrayList arrListTemp = myNetWork.getDataSource().getSnpNames();

        do {
            // -- 1, randomly get 2 snp names --
            while (snp1.compareToIgnoreCase(snp2) == 0) {
                rand = getRandomInt(0, arrListTemp.size());
                snp1 = arrListTemp.get(rand).toString().trim();
                rand = getRandomInt(0, arrListTemp.size());
                snp2 = arrListTemp.get(rand).toString().trim();
            }

            // -- 2, get the value of the 2 selected snps and permute --
            ArrayList arrListSnp1 = new ArrayList();
            ArrayList arrListSnp2 = new ArrayList();
            // -- get the selected snp data
            String[] strSnp1Data = (String[]) myNetWork.getDataSource().getHmAttributeDict().get(snp1);
            String[] strSnp2Data = (String[]) myNetWork.getDataSource().getHmAttributeDict().get(snp2);

            for (int i = 0; i < strSnp1Data.length; i++) {
                arrListSnp1.add(strSnp1Data[i]);
                arrListSnp2.add(strSnp2Data[i]);
            }// end of for loop

            String[] permutedSnp1Data = new String[strSnp1Data.length];
            String[] permutedSnp2Data = new String[strSnp2Data.length];

            // permute the data
            for (int i = 0; i < strSnp1Data.length; i++) {
                int randInt1 = getRandomInt(0, arrListSnp1.size() - 1);
                permutedSnp1Data[i] = arrListSnp1.get(randInt1).toString();
                arrListSnp1.remove(randInt1);

                int randInt2 = getRandomInt(0, arrListSnp2.size() - 1);
                permutedSnp2Data[i] = arrListSnp2.get(randInt2).toString();
                arrListSnp2.remove(randInt2);
            }

            // -- 3, get the interaction gain score --

            // set up myNetWork.getDataSource() with the permuted data
            // and then calculate the gain score
            myNetWork.getDataSource().getHmAttributeDict().put(snp1, permutedSnp1Data);
            myNetWork.getDataSource().getHmAttributeDict().put(snp2, permutedSnp2Data);
            scoreArray[loop] = 100 * myNetWork.getDataSource().interactionInformation(snp1, snp2);

            // now set up myNetWork.getDataSource() with the
            // original data to keep data integrity
            myNetWork.getDataSource().getHmAttributeDict().put(snp1, strSnp1Data);
            myNetWork.getDataSource().getHmAttributeDict().put(snp2, strSnp2Data);

        } while (++loop < stopLoop);

        // -- 4, display the list to the textbox. --
        // sort the result
        Arrays.sort(scoreArray);
        String result = "";
        for (int i = scoreArray.length - 1; i >= 0; i--) {
            result += scoreArray[i] + "\n";
        }
        // get the cutoff
        int cutoff = (int) (Integer.parseInt(jTextFieldPermuteLoopCount.getText()) * Double.parseDouble(jTextFieldFalsePositiveRisk.getText()));

        //displey the score array and the cutoff gain score
        jTextAreaPermutationList.setText(result);
        jTextFieldInteractionGainCutoff.setText(scoreArray[scoreArray.length - cutoff - 1] + "");

        setMouseDefault();
        jButtonRunNetWork.setEnabled(true);
        jButtonGetCorrelations.setEnabled(true);
}//GEN-LAST:event_jButtonRunPermutationActionPerformed

    private void jButtonShowNetworkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonShowNetworkActionPerformed
        setMouseBusy();
        showNetWork();
        
        setMouseDefault();
}//GEN-LAST:event_jButtonShowNetworkActionPerformed

    private void jButtonSaveNetworkDegreesTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveNetworkDegreesTableActionPerformed
        setMouseBusy();
        //save file information
        jTextFieldStatus.setText("network degree file is saving...");

        //get the file name to be saved
        int fileOpenReturnValue = jFileChooserMain.showSaveDialog(new java.awt.Component() {
        });

        //if file name is choosed, then save to this file
        if (fileOpenReturnValue == JFileChooser.APPROVE_OPTION) {
            String filename = jFileChooserMain.getSelectedFile().getAbsolutePath();
            int rowSize = jTableNetworkDegrees.getRowCount();
            try {
                FileWriter fw = new FileWriter(filename);
                BufferedWriter writer = new BufferedWriter(fw);

                for (int i = 0; i < rowSize; i++) {
                    writer.write(jTableNetworkDegrees.getValueAt(i, 0) + "\t");
                    writer.write(jTableNetworkDegrees.getValueAt(i, 1) + "\n");
                }
                writer.close();
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e.toString());
            }
        } else if (fileOpenReturnValue == JFileChooser.CANCEL_OPTION) {
        }
        jTextFieldStatus.setText("network degree file is saved!");
        setMouseDefault();
}//GEN-LAST:event_jButtonSaveNetworkDegreesTableActionPerformed

    private void jButtonSaveMatrixActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveMatrixActionPerformed
        setMouseBusy();
        jTextFieldStatus.setText("matrix file is saving...");
        //get the file
        //        JFileChooser jFileChooserMain = new JFileChooser();
        int fileOpenReturnValue = jFileChooserMain.showSaveDialog(new java.awt.Component() {
        });

        if (fileOpenReturnValue == JFileChooser.APPROVE_OPTION) {
            String saveFile = jFileChooserMain.getSelectedFile().getAbsolutePath();
            myNetWork.getAdjacencyMatrix(saveFile);
            setMouseDefault();
            jTextFieldStatus.setText("matrix file is saved.");
        } else if (fileOpenReturnValue == JFileChooser.CANCEL_OPTION) {
            setMouseDefault();
        }
}//GEN-LAST:event_jButtonSaveMatrixActionPerformed

    private void jButtonSaveSifActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveSifActionPerformed
        setMouseBusy();
        jTextFieldStatus.setText("sif file is saving...");
        //get the file
        int fileOpenReturnValue = jFileChooserMain.showSaveDialog(new java.awt.Component() {
        });

        if (fileOpenReturnValue == JFileChooser.APPROVE_OPTION) {
            String saveFile = jFileChooserMain.getSelectedFile().getAbsolutePath();
            //get the date need to be wroten
            //-- if the checkbox is checked, then add the row to the network --
            ArrayList arrListSelectedSNP4Network = new ArrayList();
            for (int i = 0; i < jTableInteractionGainResult.getRowCount(); i++) {
                if (jTableInteractionGainResult.getValueAt(i, GainTableModel.SELECTED_INDEX).toString().compareToIgnoreCase("true") == 0) {
                    String value = jTableInteractionGainResult.getValueAt(i, GainTableModel.SNP1_INDEX).toString() + "\t" + jTableInteractionGainResult.getValueAt(i, GainTableModel.INTERACTIONGAIN_INDEX).toString() + "\t" + jTableInteractionGainResult.getValueAt(i, GainTableModel.SNP2_INDEX).toString();
                    if (!arrListSelectedSNP4Network.contains(value)) {
                        arrListSelectedSNP4Network.add(value);
                    }
                }
            }//end of for loop
            if (arrListSelectedSNP4Network.isEmpty()) {
                JOptionPane.showMessageDialog(null, "no snp is selected!");
            } else {
                saveSifNumric(arrListSelectedSNP4Network, saveFile);
                setMouseDefault();
                jTextFieldStatus.setText("sif file is saved.");
            }
        } else if (fileOpenReturnValue == JFileChooser.CANCEL_OPTION) {
            setMouseDefault();
        }
}//GEN-LAST:event_jButtonSaveSifActionPerformed

    private void jButtonSaveGainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveGainActionPerformed
        setMouseBusy();

        ArrayList arrListSelectedSNP4Network = new ArrayList();
        for (int i = 0; i < jTableInteractionGainResult.getRowCount(); i++) {
            if (jTableInteractionGainResult.getValueAt(i, GainTableModel.SELECTED_INDEX).toString().compareToIgnoreCase("true") == 0) {
                String value = jTableInteractionGainResult.getValueAt(i, GainTableModel.SNP1_INDEX).toString() + "\t" + jTableInteractionGainResult.getValueAt(i, GainTableModel.INTERACTIONGAIN_INDEX).toString() + "\t" + jTableInteractionGainResult.getValueAt(i, GainTableModel.SNP2_INDEX).toString();
                if (!arrListSelectedSNP4Network.contains(value)) {
                    arrListSelectedSNP4Network.add(value);
                }
            }
        }//end of for loop
        if (arrListSelectedSNP4Network.isEmpty()) {
            JOptionPane.showMessageDialog(null, "no SNP is selected!");
            setMouseDefault();
        } else {
            jTextFieldStatus.setText("gain file is saving...");

            //get the file
            int fileOpenReturnValue = jFileChooserMain.showSaveDialog(new java.awt.Component() {
            });

            if (fileOpenReturnValue == JFileChooser.APPROVE_OPTION) {
                String saveFile = jFileChooserMain.getSelectedFile().getAbsolutePath();
                saveGainTable(saveFile);

                setMouseDefault();
                jTextFieldStatus.setText("gain file is saved.");
            } else if (fileOpenReturnValue == JFileChooser.CANCEL_OPTION) {
                setMouseDefault();
            }
        }
}//GEN-LAST:event_jButtonSaveGainActionPerformed

    private void jButtonRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRefreshActionPerformed
        //set the new range:
        int rowSize = jTableInteractionGainResult.getRowCount();
        double min = (Double.parseDouble(jTextFieldMinRange.getText()));
        double max = (Double.parseDouble(jTextFieldMaxRange.getText()));

        //build the table by removing the rows which is not in the range
        for (int i = 0; i < rowSize; i++) {
            if (Double.parseDouble(jTableInteractionGainResult.getValueAt(i, GainTableModel.INTERACTIONGAIN_INDEX).toString()) > max || Double.parseDouble(jTableInteractionGainResult.getValueAt(i, GainTableModel.INTERACTIONGAIN_INDEX).toString()) < min) {
                //delete the row
                myShowGainTableModel.removeRow(i);
                myShowGainTableModel.setRowCount(--rowSize);
                jTableCorrelations.revalidate();
                i--;
            }
        }//end of for loop
        jTextFieldStatus.setText("Table is refreshed.");
}//GEN-LAST:event_jButtonRefreshActionPerformed

    private void jTextFieldMaxRangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldMaxRangeActionPerformed
        jTextFieldStatus.setText("max value is set to:" + jTextFieldMaxRange.getText());
}//GEN-LAST:event_jTextFieldMaxRangeActionPerformed

    private void jTextFieldMinRangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldMinRangeActionPerformed
        if (Double.parseDouble(jTextFieldMinRange.getText()) < Double.parseDouble((jTextFieldCutoff.getText()))) {
            JOptionPane.showMessageDialog(null, "the value you input should be greater than the cutoff value");
        }
        jTextFieldStatus.setText("min value is set to:" + jTextFieldMinRange.getText());
}//GEN-LAST:event_jTextFieldMinRangeActionPerformed

    private void jButtonRunNetWorkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRunNetWorkActionPerformed
        setMouseBusy();
        jTextFieldStatus.setText("network is building...");

        //progress bar part : another thread
        jProgressBarRun.setOpaque(true);
        jProgressBarRun.setIndeterminate(true);
        jProgressBarRun.setStringPainted(false);
        jProgressBarRun.setVisible(true);

        Runnable setProgressBar = new Runnable() {

            public void run() {
                buildNetworkTable();
                buildNetworkDegreeTable();

                if (!myNetWork.isStop()) {
                    jScrollPaneInteractionResult.setViewportView(jTableInteractionGainResult);
                    jTextFieldStatus.setText("network is built");
                    jButtonShowNetwork.setEnabled(true);
                    jMenuItemShowNetwork.setEnabled(true);
                } else {
                    jTextFieldStatus.setText("Stoped by user");
                }
                jButtonSaveMatrix.setEnabled(true);
                jButtonSaveSif.setEnabled(true);
                jButtonSaveGain.setEnabled(true);
                jButtonSaveGain.setEnabled(true);
                jProgressBarRun.setVisible(false);
                setMouseDefault();
                SwingUtilities.invokeLater(new Runnable() {

                    public void run() {
                    }
                });
            }
        };//end of setProgreeBar
        Thread threadProgressBar = new Thread(setProgressBar);
        threadProgressBar.start();
}//GEN-LAST:event_jButtonRunNetWorkActionPerformed

    private void jButtonGetCorrelationsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGetCorrelationsActionPerformed
        setMouseBusy();
        jTextFieldStatus.setText("Finding correlations...");
        //        arrListRemain.clear();
        //        arrListRemainRemoveList.clear();
        //        vecRemoveNameList.clear();

        //progress bar part : another thread
        jProgressBarRun.setOpaque(true);
        jProgressBarRun.setIndeterminate(true);
        jProgressBarRun.setStringPainted(false);
        jProgressBarRun.setVisible(true);

        Runnable setProgressBar = new Runnable() {

            public void run() {
                getCorrelations();

                if (!myNetWork.isStop()) {
                    jScrollPaneCorrelationTable.setViewportView(jTableCorrelations);
                    jTextFieldStatus.setText("Finding correlations finished.");
                    jButtonTableRemove.setEnabled(true);
                    jMenuItemRemoveFromCorrelatedTable.setEnabled(true);
                } else {
                    jTextFieldStatus.setText("Calculation stoped by user");
                }
                jProgressBarRun.setVisible(false);
                setMouseDefault();
                SwingUtilities.invokeLater(new Runnable() {

                    public void run() {
                        //                        jProgressBarRun.setValue(100);
                    }
                });
            }//end of run()
        };
        Thread threadProgressBar = new Thread(setProgressBar);
        threadProgressBar.start();
}//GEN-LAST:event_jButtonGetCorrelationsActionPerformed

    private void jButtonRemaingRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemaingRemoveActionPerformed

        // check the table, if column is checked, then add it to the removed snp name list
        for (int i = 0; i < jTableCorrelationsRemain.getRowCount(); i++) {
            if (jTableCorrelationsRemain.getValueAt(i, RemainCorrelationTableModel.SNPSELECTED_INDEX).toString().compareToIgnoreCase("true") == 0) {
                if (!arrListRemainRemoveList.contains(jTableCorrelationsRemain.getValueAt(i, RemainCorrelationTableModel.SNP_INDEX).toString())) {
                    arrListRemainRemoveList.add(jTableCorrelationsRemain.getValueAt(i, RemainCorrelationTableModel.SNP_INDEX).toString());
                }
                if (arrListRemain.contains(jTableCorrelationsRemain.getValueAt(i, RemainCorrelationTableModel.SNP_INDEX).toString())) {
                    arrListRemain.remove(jTableCorrelationsRemain.getValueAt(i, RemainCorrelationTableModel.SNP_INDEX).toString());
                }
            } //end of if()
        } //end of for loop

        //get the remove list
        String[] strArray = new String[arrListRemainRemoveList.size()];

        //set remove history list with the snp to be removed
        for (int i = 0; i < arrListRemainRemoveList.size(); i++) {
            strArray[i] = arrListRemainRemoveList.get(i).toString().trim();
            if (!vecRemoveNameList.contains(strArray[i])) {
                vecRemoveNameList.addElement(strArray[i]);
            } //end of if()
        } //end of for loop

        //set remove history with the removed snp name
        String strTemp = "";
        for (int i = 0; i < vecRemoveNameList.size(); i++) {
            strTemp += vecRemoveNameList.get(i).toString() + "\n";
        }
        jTextAreaRemoveHistory.setText(strTemp);

        //remove snps from the table.
        removeSnpFromRemainCorrelationTable(strArray, jTableCorrelationsRemain, true);
        setNumberofAttrsAndSamples(jLabelNumberOfAttrsAndSample,
                myNetWork.getNumbeOfAttributes() - vecRemoveNameList.size(),
                myNetWork.getNumbeOfSamples());
        jTextFieldStatus.setText("new table row size is : " + jTableCorrelationsRemain.getRowCount());
}//GEN-LAST:event_jButtonRemaingRemoveActionPerformed

    private void jButtonSaveCorrelationsRemainDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveCorrelationsRemainDataActionPerformed
        setMouseBusy();

        //save file information
        jTextFieldStatus.setText("Correlations remain attrbutes data file are saving...");

        //get the file name to be saved
        int fileOpenReturnValue = jFileChooserMain.showSaveDialog(new java.awt.Component() {
        });

        //if file name is choosed, then save to this file
        if (fileOpenReturnValue == JFileChooser.APPROVE_OPTION) {
            //cut the input file
            SubArff subArff = new SubArff(arrListRemain, inputFile);
            cutInFileByVarListFile(subArff, jFileChooserMain.getSelectedFile().getAbsolutePath());

        } else if (fileOpenReturnValue == JFileChooser.CANCEL_OPTION) {
        }
        jTextFieldStatus.setText("Correlations remain attrbutes data file is saved!");
        setMouseDefault();
}//GEN-LAST:event_jButtonSaveCorrelationsRemainDataActionPerformed

    private void jTableCorrelationsRemainMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableCorrelationsRemainMouseClicked
        int column = jTableCorrelationsRemain.getSelectedColumn();
        if (column == ((RemainCorrelationTableModel) jTableCorrelationsRemain.getModel()).SNPSELECTED_INDEX) {
            int row = jTableCorrelationsRemain.getSelectedRow();

            String value = jTableCorrelationsRemain.getValueAt(row, column).toString();
            String varName = jTableCorrelationsRemain.getValueAt(row, RemainCorrelationTableModel.SNP_INDEX).toString();
            if (value.compareToIgnoreCase("true") == 0) {
                if (arrListRemain.contains(varName)) {
                    arrListRemain.remove(varName);
                }
                if (!arrListRemainRemoveList.contains(varName)) {
                    arrListRemainRemoveList.add(varName);
                }
            } else {
                if (!arrListRemain.contains(varName)) {
                    arrListRemain.add(varName);
                }
                if (arrListRemainRemoveList.contains(varName)) {
                    arrListRemainRemoveList.remove(varName);
                }
            }
            jTextFieldStatus.setText("the current row is:" + "\t" + row);
        }
}//GEN-LAST:event_jTableCorrelationsRemainMouseClicked

    private void jButtonSaveCorrelationsTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveCorrelationsTableActionPerformed
        setMouseBusy();
        jTextFieldStatus.setText("Correlations are saving...");

        //get the file name to be saved
        //        JFileChooser jFileChooserMain = new JFileChooser();
        int fileOpenReturnValue = jFileChooserMain.showSaveDialog(new java.awt.Component() {
        });

        //if file name is choosed, then save to this file
        if (fileOpenReturnValue == JFileChooser.APPROVE_OPTION) {
            String saveFile = jFileChooserMain.getSelectedFile().getAbsolutePath();
            saveCorrelations(saveFile);
            jTextFieldStatus.setText("Correlations file is saved.");
        } else if (fileOpenReturnValue == JFileChooser.CANCEL_OPTION) {
        }
        setMouseDefault();
}//GEN-LAST:event_jButtonSaveCorrelationsTableActionPerformed

    private void jButtonTableRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTableRemoveActionPerformed
        setMouseBusy();
        removeVariable();
        setMouseDefault();
}//GEN-LAST:event_jButtonTableRemoveActionPerformed

    private void jTableCorrelationsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableCorrelationsMouseClicked
        int column = jTableCorrelations.getSelectedColumn();
        if (column == CorrelationTableModel.SNP1Selected_INDEX ||
                column == CorrelationTableModel.SNP2Selected_INDEX) {
            int row = jTableCorrelations.getSelectedRow();

            String value = jTableCorrelations.getValueAt(row, column).toString();
            String varName = jTableCorrelations.getValueAt(row, column + 1).toString();
            if (value.compareToIgnoreCase("true") == 0) {
                if (!vecRemoveNameList.contains(varName)) {
                    vecRemoveNameList.addElement(varName);
                }
            } else {
                if (vecRemoveNameList.contains(varName)) {
                    vecRemoveNameList.removeElement(varName);
                }
            }
            jTextFieldStatus.setText("the current row is:" + "\t" + row + "\t" + "remove list : " + vecRemoveNameList.size());
        }
}//GEN-LAST:event_jTableCorrelationsMouseClicked

    private void jButtonRevertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRevertActionPerformed
        setMouseBusy();
        jTextFieldStatus.setText("Current input file is now reverted to the original file.");
        finalInputFile = inputFile;
        //initialize the network with finalInput
        //        myNetWork = new NetWork(new InformationTheoretica(finalInputFile),"init");

        //show finalInputfile in the display area
        showFinalInputfile();

        //create the remaining table based on the finalInputFile.
        createRemainingTable();

        setMouseDefault();
}//GEN-LAST:event_jButtonRevertActionPerformed

    private void jButtonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonApplyActionPerformed
        setMouseBusy();
        jTextFieldStatus.setText("Current input file contains only the selected attributes.");

        //progress bar part : another thread
        // set progress bar visible
        jProgressBarRun.setOpaque(true);
        jProgressBarRun.setIndeterminate(true);
        jProgressBarRun.setStringPainted(false);
        jProgressBarRun.setVisible(true);


        Runnable setProgressBar = new Runnable() {

            public void run() {
                //cut the input file
                SubArff subArff = new SubArff(inputAttrNameFile,
                        inputFile);
                finalInputFile = inputFile + ".tab";
                cutInFileByVarListFile(subArff, finalInputFile);

                //show finalInputfile in the display area
                showFinalInputfile();

                //create the remaining table based on the finalInputFile.
                createRemainingTable();

                //enable other buttons
                jButtonRevert.setEnabled(true);
                jMenuItemRevert.setEnabled(true);
                jButtonRunNetWork.setEnabled(true);
                jMenuItemRunNetwork.setEnabled(true);

                setMouseDefault();
                //set progress bar unvisible
                jProgressBarRun.setIndeterminate(false);
                jProgressBarRun.setStringPainted(true);
                jProgressBarRun.setVisible(false);

                SwingUtilities.invokeLater(new Runnable() {

                    public void run() {
                    }
                });
            }
        };
        Thread threadProgressBar = new Thread(setProgressBar);
        threadProgressBar.start();
    }//GEN-LAST:event_jButtonApplyActionPerformed

    private void jButtonBrowseFilterFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBrowseFilterFileActionPerformed
        setMouseBusy();
        //get the file from the file choose dialog
        jFileChooserMain.removeChoosableFileFilter(myOpenFileFilter);
        int fileOpenReturnValue = jFileChooserMain.showOpenDialog(this);

        if (fileOpenReturnValue == JFileChooser.APPROVE_OPTION) {
            inputAttrNameFile = jFileChooserMain.getSelectedFile().getAbsolutePath();
            jTextFieldOptionAttribute.setText(inputAttrNameFile);
            String strAllfile = "";
            try {
                FileReader fr = new FileReader(inputAttrNameFile);
                BufferedReader br = new BufferedReader(fr);
                // strRow is used to read line from file
                String strRow = new String();

                while ((strRow = br.readLine()) != null) {
                    strAllfile += strRow.trim() + "\n";
                }// end of while
                br.close();
                fr.close();
            } catch (FileNotFoundException e) {
                JOptionPane.showMessageDialog(null, "Attributes file not found!");
            } catch (IOException e) {
                // catch possible io errors from readLine()
                JOptionPane.showMessageDialog(null, "file is not rigt!");
            }

            String[] remainNameList = strAllfile.split("\n");

            removeSnpFromRemainCorrelationTable(remainNameList, jTableCorrelationsRemain, false);

            //setup the status bar with file path information
            jTextAreaExampleFileShow.setText(strAllfile);
            jTextFieldStatus.setText(inputAttrNameFile);
            jButtonApply.setEnabled(true);
            jMenuItemApply.setEnabled(true);

        } else if (fileOpenReturnValue == JFileChooser.CANCEL_OPTION) {
        }

        setMouseDefault();
}//GEN-LAST:event_jButtonBrowseFilterFileActionPerformed

    private void jButtonBrowseInFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBrowseInFileActionPerformed
        setMouseBusy();

        //get the file from a file choose diag.
        jFileChooserMain.setFileFilter(myOpenFileFilter);
        int fileOpenReturnValue = jFileChooserMain.showOpenDialog(this);
        if (fileOpenReturnValue == JFileChooser.APPROVE_OPTION) {
            inputFile = jFileChooserMain.getSelectedFile().getAbsolutePath();
            finalInputFile = inputFile;

            //show finalInputfile in the display area
            showFinalInputfile();

        } else if (fileOpenReturnValue == JFileChooser.CANCEL_OPTION) {
            //if no file is chosen, default file will be loaded and initialize the network
        }
        //create the remaining table based on the finalInputFile.
        createRemainingTable();
        setMouseDefault();
}//GEN-LAST:event_jButtonBrowseInFileActionPerformed

    /**
     * this method will randomly permute the selected snp's value
     */
    //*************************************************
    //   user defined methods
    //*************************************************
    private int getRandomInt(int min, int max) {
        if (min < max) {
            return ((int) (((max - min) * (Math.random()) + 0.5)) + min);
        } else {
            return ((int) (((min - max) * (Math.random()) + 0.5)) + min);
        }
    }

    private void saveSifNumric(ArrayList arrList, String fileName) {
        //arrList format:  "node1    numeric_edge    node2"
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
            // System.out.println("node1" + "\tedge\t" + "node2");
            for (int i = 0; i < arrList.size(); i++) {
                writer.write(arrList.get(i).toString() + "\n");
            }
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     *  to remove the selected variables from the correlations table
     */
    private void removeVariable() {
        arrListRemain.clear();
        arrListRemainRemoveList.clear();
        //**************************************************************
        // remove the rows from the table where the variable is in selected list
        //**************************************************************
        Vector removeName = new Vector(vecRemoveNameList); //for remove name
        int tableRowSize = jTableCorrelations.getRowCount();
        Vector vecSnp1 = new Vector(tableRowSize); //for snp1 name
        Vector vecSnp2 = new Vector(tableRowSize); // for snp2 name
//       Vector vecRemainSnps = new Vector(2*tableRowSize);


        //************  step 1: find the removed variable *****************
        //vecRemoveNameList is the vector of the removed variable
        //and it is initialzed in tableMouseClick event handler

        //************  step 2: find the variable in the table ************

        //initialize the vecSnp1 & vecSnp2
        for (int i = 0; i < tableRowSize; i++) {
            vecSnp1.add(jTableCorrelations.getValueAt(i, CorrelationTableModel.SNP1_INDEX));
            vecSnp2.add(jTableCorrelations.getValueAt(i, CorrelationTableModel.SNP2_INDEX));
        }

        //************  step 3: record the row number ********************
        for (int i = 0; i < tableRowSize; i++) { //outter for loop
            String strSnp1 = (String) vecSnp1.elementAt(i);
            String strSnp2 = (String) vecSnp2.elementAt(i);
            for (int j = 0; j < removeName.size(); j++) {//inner for loop
                String strRemoveName = (String) removeName.elementAt(j);
                boolean choose = false;

                //check if snp1 is in the remove list
                if (strSnp1.compareToIgnoreCase(strRemoveName) == 0) {
                    choose = true;
                    jTableCorrelations.setValueAt(true, i, CorrelationTableModel.SNP1Selected_INDEX);
                    if (arrListRemain.contains(strSnp1)) {
                        arrListRemain.remove(strSnp1);
                    }
                } else {
                    //if snp1 is not in the remove list, add to the remain list
                    if (!arrListRemain.contains(strSnp1)) {
                        arrListRemain.add(strSnp1);
                    }
                }

                //check if snp2 is in the remove list
                if (strSnp2.compareToIgnoreCase(strRemoveName) == 0) {
                    choose = true;
                    jTableCorrelations.setValueAt(true, i, CorrelationTableModel.SNP2Selected_INDEX);
                    if (arrListRemain.contains(strSnp2)) {
                        arrListRemain.remove(strSnp2);
                    }
                } else {
                    //if snp2 is not in the remove list, add to the remain list
                    if (!arrListRemain.contains(strSnp2)) {
                        arrListRemain.add(strSnp2);
                    }
                }

                //remove the line where snp1 or snp2 is in the remove list
                if (choose) {
                    myShowCorrTableModel.removeRow(i);
                    myShowCorrTableModel.setRowCount(--tableRowSize);
                    jTableCorrelations.revalidate();
                    vecSnp1.removeElementAt(i);
                    vecSnp2.removeElementAt(i);
                    i--;
                    break;
                }//end if
            }//end inner for loop
        }//end outter for loop

        //show the removed variables to the remove history windows
        String toTextArea = "";
        for (int i = 0; i < vecRemoveNameList.size(); i++) {
            toTextArea += vecRemoveNameList.elementAt(i).toString() + "\n";
        }

        String[] strArray = new String[vecRemoveNameList.size()];
        for (int i = 0; i < vecRemoveNameList.size(); i++) {
            strArray[i] = vecRemoveNameList.get(i).toString().trim();
        }

        removeSnpFromRemainCorrelationTable(strArray, jTableCorrelationsRemain, true);

        jTextAreaRemoveHistory.setText(toTextArea);
        setNumberofAttrsAndSamples(jLabelNumberOfAttrsAndSample,
                myNetWork.getNumbeOfAttributes() - vecRemoveNameList.size(),
                myNetWork.getNumbeOfSamples());
        jTextFieldStatus.setText("new table row size is : " + jTableCorrelations.getRowCount());
    }//end of removeVariable()

    /**
     * 
     * @param filename   the name of the file to be saved
     *
     * save the correlation tables to a file
     */
    private void saveCorrelations(String filename) {
        int rowSize = jTableCorrelations.getRowCount();
        try {
            FileWriter fw = new FileWriter(filename);
            BufferedWriter writer = new BufferedWriter(fw);

            for (int i = 0; i < rowSize; i++) {
                writer.write(jTableCorrelations.getValueAt(i, CorrelationTableModel.SNP1_INDEX) + "\t");
                writer.write(jTableCorrelations.getValueAt(i, CorrelationTableModel.SCORE_INDEX) + "\t");
                writer.write(jTableCorrelations.getValueAt(i, CorrelationTableModel.SNP2_INDEX) + "\n");
            }

            writer.close();
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.toString());
        }
    }//end of saveCorrelations()

    /**
     * 
     * @param filename   the name of the file to be saved
     *
     * save the correlation ramain tables to a file
     */
    private void saveRemaining(String filename) {
        int rowSize = jTableCorrelationsRemain.getRowCount();
        try {
            FileWriter fw = new FileWriter(filename);
            BufferedWriter writer = new BufferedWriter(fw);

            for (int i = 0; i < rowSize; i++) {
                writer.write(jTableCorrelationsRemain.getValueAt(i, RemainCorrelationTableModel.SNP_INDEX) + "\n");
            }
            writer.close();
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.toString());
        }
    }//end of saveCorrelations()

    /**
     *  calculate the correlations 
     */
    private void getCorrelations() {

        if (jButtonGetCorrelations.getText().compareToIgnoreCase("stop") != 0) {
            //-- calculate the correlations
//            myNetWork.setThreshold(Double.parseDouble(jTextFieldSymmetric.getText()));
//            myNetWork.setCutoff(Double.parseDouble(jTextFieldCutoff.getText()));
//            myNetWork.setChoose(jButtonGetCorrelations.getText());
            myNetWork = new NetWork(new InformationTheoretica(finalInputFile),
                    jButtonGetCorrelations.getText(),
                    Double.parseDouble(jTextFieldSymmetric.getText()),
                    Double.parseDouble(jTextFieldCutoff.getText()));
            myNetWork.setName("Thread-correlation" + correlationThreadCount++);
            myNetWork.start();
            jButtonGetCorrelations.setText("Stop");
        } else {
            myNetWork.shutDown();
        }

        try {
            myNetWork.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        jButtonGetCorrelations.setText("Calculate");

        if (!myNetWork.isStop()) {
            // -- output correlations --
            Vector fileterNameList = myNetWork.getFilteredNamelist();

            //show to the result window
            Vector columnName = new Vector();//for the jTable name part
            Vector rowData = new Vector();  //for the jTable data part

            // -- get the column name part (snp1Select snp1 score snp1Select snp2) --
            String[] strArrayName = fileterNameList.elementAt(0).toString().trim().split("\\t");
            //-- first column
            columnName.addElement("SNP1Selected"); //for snp1 check box column
            //-- 2nd and 3rd column
            int i = 0;
            for (i = 0; i < strArrayName.length - 1; i++) {
                columnName.addElement(strArrayName[i]);
            }
            //-- 4th column --
            columnName.addElement("SNP2Selected");//for snp2 check box column
            //-- last column
            columnName.addElement(strArrayName[i]);
            //--- end of column name part --

            //-- get the data part --
            for (i = 1; i < fileterNameList.size() && !myNetWork.isStop(); i++) {
                Vector temp = new Vector();
                String[] strArray = fileterNameList.elementAt(i).toString().trim().split("\\t");
                temp.addElement(new Boolean(false));
                int j = 0;
                for (j = 0; j < strArray.length - 1; j++) {
                    temp.addElement(strArray[j]);
                }
                temp.addElement(new Boolean(false));
                temp.addElement(strArray[j]);
                rowData.addElement(temp); //for the jTable data part
            }
            //-- end of get the data part --

            //-- create the table --
            myShowCorrTableModel = new CorrelationTableModel(columnName, rowData);
            jTableCorrelations.setModel(myShowCorrTableModel);
            jTableCorrelations.setPreferredScrollableViewportSize(new Dimension(400, 90));
            jTableCorrelations.setCellSelectionEnabled(true);
            jTableCorrelations.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

                public void valueChanged(ListSelectionEvent e) {
                    jTextFieldStatus.setText("remove list size is: " + vecRemoveNameList.size());
                }
            });
        }
    } //end of getCorrelations()

    /**
     * save the interaction gain result table
     */
    private void saveGainTable(String saveFile) {
        int rowSize = jTableInteractionGainResult.getRowCount();
        int colSize = jTableInteractionGainResult.getColumnCount();

        try {
            FileWriter fw = new FileWriter(saveFile);
            BufferedWriter writer = new BufferedWriter(fw);

            for (int i = 0; i < rowSize; i++) {
                int j = 0;
                for (j = 0; j < colSize - 1; j++) {
                    writer.write(jTableInteractionGainResult.getValueAt(i, j) + "\t");
                }
                writer.write(jTableInteractionGainResult.getValueAt(i, j) + "\n");
            }
            writer.close();
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, e.toString());
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.toString());
            System.exit(1);
        }
    } // end of save gain table

    /**
     *  cut the input file by only variables in the list file
     */
    private void cutInFileByVarListFile(SubArff subArff, String outFilename) {

        //initianlize the network with finalInput
        subArff.toTabFile(subArff.getNameList(), outFilename);
        myNetWork = new NetWork(new InformationTheoretica(outFilename), "init");
        try {
            FileReader fr = new FileReader(outFilename);
            BufferedReader br = new BufferedReader(fr);
            String strRow = "";
            String strResult = "";

            while ((strRow = br.readLine()) != null) {
                strResult += strRow + "\n";
            }// end of while

            jTextAreaExampleFileShow.setText(strResult);
            br.close();
            fr.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "IOException error in file loading");
        } catch (IOException ee) {
            ee.printStackTrace();
            JOptionPane.showMessageDialog(null, "IOException error in file loading");
        }
    }

    /**
     * set the mouse to busy status 
     */
    private void setMouseBusy() {
        jTabbedPaneMain.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    }

    /**
     * set the mouse to default status 
     */
    private void setMouseDefault() {
        jTabbedPaneMain.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }

    /**
     *  build net work table
     */
    private void buildNetworkTable() {

        //-- calculate the interaction gain --
        if (jButtonRunNetWork.getText().compareToIgnoreCase("stop") != 0) {
            //-- calculate the correlations
//            myNetWork.setThreshold(Double.parseDouble(jTextFieldSymmetric.getText()));
//            myNetWork.setCutoff(Double.parseDouble(jTextFieldCutoff.getText()));
//            myNetWork.setChoose(jButtonRunNetWork.getText());
            myNetWork = new NetWork(new InformationTheoretica(finalInputFile),
                    jButtonRunNetWork.getText(),
                    Double.parseDouble(jTextFieldSymmetric.getText()),
                    Double.parseDouble(jTextFieldCutoff.getText()));
            myNetWork.setName("network-Thread" + networkThreadCount++);
            myNetWork.start();
            jButtonRunNetWork.setText("Stop");
        } else {
            myNetWork.shutDown();
        }

        try {
            myNetWork.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        jButtonRunNetWork.setText("Run");

        if (!myNetWork.isStop()) {
            Vector vecGains = myNetWork.getSortedInteractionGain(false);

            //set the min and max text field
            jTextFieldMinRange.setText((Double.parseDouble(jTextFieldCutoff.getText())) * 100 + "");
            jTextFieldMaxRange.setText(myNetWork.getMaxInteractionGain() + "");

            //-- get the column name --

            String[] arrayName = vecGains.elementAt(0).toString().trim().split("\\t");
            Vector vecName = new Vector();
            // -- first column name --
            vecName.addElement("Selected");//for check box column
            // -- other column name --
            for (int i = 0; i < arrayName.length; i++) {
                vecName.addElement(arrayName[i]);
            }
            arrayName = null;
            //-- end of get the column name --

            //-- get the data part --
            Vector rowData = new Vector();
            for (int i = 1; i < vecGains.size() && !myNetWork.isStop(); i++) {
                Vector temp = new Vector();
                temp.addElement(new Boolean(false));
                String[] strArray = vecGains.elementAt(i).toString().trim().split("\\t");
                for (int j = 0; j < strArray.length; j++) {
                    temp.addElement(strArray[j]);
                }
                rowData.addElement(temp); //for the jTable data part
            }
            //-- end of get the data part --

            //-- create the table --
            myShowGainTableModel = new GainTableModel(vecName, rowData);
            jTableInteractionGainResult = new JTable(myShowGainTableModel);

            //set sort manager 
            new SortManager(jTableInteractionGainResult);

            jTableInteractionGainResult.setPreferredScrollableViewportSize(new Dimension(400, 90));
            jTableInteractionGainResult.setCellSelectionEnabled(true);

            //get table's ListSelectionModel and set its listener
            jTableInteractionGainResult.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

                public void valueChanged(ListSelectionEvent e) {
                    int column = jTableInteractionGainResult.getSelectedColumn();
                    if (column == GainTableModel.SELECTED_INDEX) {
                        int row = jTableInteractionGainResult.getSelectedRow();
                        if (row >= 0) {
                            String selectedFlag = jTableInteractionGainResult.getValueAt(row, column).toString();
                            if (selectedFlag.compareToIgnoreCase("true") == 0) {
                                jTextFieldStatus.setText("row " + jTableInteractionGainResult.getSelectedRow() + " is selected");
                            } else {
                                jTextFieldStatus.setText("row " + jTableInteractionGainResult.getSelectedRow() + " is unselected");
                            }
                        }
                    }//end of if(column == ...
                } //end of valueChanged method
            });
        }//end of if (!myNetWork.isStop()) 
    } //end of buildnetworkTable()

    /**
     *  build net work degree table
     */
    private void buildNetworkDegreeTable() {

        // -- get the number of connections --
        myNetWork.getNumberOfConnections();//hash map, key is the node name, value is the NumofConn

        // -- build the table --
        if (!myNetWork.isStop()) {

            //-- get the column name --
            Vector vecName = new Vector();
            // -- first column name --
            vecName.addElement("Node (SNP name)");
            // -- other column name --
            vecName.addElement("Degree");
            //-- end of get the column name --

            //-- get the data part --
            Iterator it = myNetWork.getNumberOfConnections().keySet().iterator();
            Vector rowData = new Vector();
            while (it.hasNext()) {
                Vector temp = new Vector();
                Object key = it.next();
                Object value = myNetWork.getNumberOfConnections().get(key);
                temp.addElement(key);
                temp.addElement(value);
                rowData.addElement(temp);
            }
            //-- end of get the data part --

            //-- create the table --
            DefaultTableModel dtm = new DefaultTableModel(rowData, vecName);
            jTableNetworkDegrees = new JTable(dtm);

            //set sort manager
            new SortManager(jTableNetworkDegrees, 1);

            jTableNetworkDegrees.setPreferredScrollableViewportSize(new Dimension(400, 90));
            jTableNetworkDegrees.setCellSelectionEnabled(true);

            jScrollPaneNetworkDegrees.setViewportView(jTableNetworkDegrees);
            jButtonSaveNetworkDegreesTable.setEnabled(true);

        }//end of if (!myNetWork.isStop())
    } //end of buildnetworkDegreeTable()

    private void showFinalInputfile() throws HeadlessException {
        //-- show file contents in the table --
        String strAllfile = "";
        if (jCheckBoxShowFileInfo.isSelected()) {
            try {
                FileReader fr = new FileReader(finalInputFile);
                BufferedReader br = new BufferedReader(fr);
                // strRow is used to read line from file
                String strRow = new String();
                while ((strRow = br.readLine()) != null) {
                    strAllfile += strRow + "\n";
                } // end of while
                br.close();
                fr.close();
            } catch (IOException e) {
                // catch possible io errors from readLine()
                JOptionPane.showMessageDialog(null, "IOException error in input file loading");
            }
        } //end if
        //-- setup the status bar with file path information --
        jTextAreaExampleFileShow.setText(strAllfile);
        jTextFieldLoadData.setText(inputFile);
        jTextFieldStatus.setText(inputFile);
        //-- enable the calculate button --
        jButtonGetCorrelations.setEnabled(true);
        jMenuItemCalculate.setEnabled(true);
        jButtonRunNetWork.setEnabled(true);
        jMenuItemRunNetwork.setEnabled(true);
    }

    /**
     *  show the net work based on the saved xml file
     */
    private void showNetWork() {
        //-- if the checkbox is checked, then add the row to the network --
        ArrayList arrListSelectedSNP4Network = new ArrayList();
        for (int i = 0; i < jTableInteractionGainResult.getRowCount(); i++) {
            String value = jTableInteractionGainResult.getValueAt(i, GainTableModel.SNP1_INDEX).toString() + "\t" + jTableInteractionGainResult.getValueAt(i, GainTableModel.SNP2_INDEX).toString() + "\t" + jTableInteractionGainResult.getValueAt(i, GainTableModel.INTERACTIONGAIN_INDEX).toString();
            if (jTableInteractionGainResult.getValueAt(i, GainTableModel.SELECTED_INDEX).toString().compareToIgnoreCase("true") == 0) {
                if (!arrListSelectedSNP4Network.contains(value)) {
                    arrListSelectedSNP4Network.add(value);
                }
            }
        }

        if (arrListSelectedSNP4Network.isEmpty()) {
            JOptionPane.showMessageDialog(null, "no snp is selected!");
        } else {
            // -- 1st step : build the xml file --
            TreeMap tmNode = new TreeMap(); //for node information 
            int value = 1; // for index of node

            String[] strEdge = new String[arrListSelectedSNP4Network.size()]; // for edge information

            // -- initialize the variables of node and edge --
            for (int i = 0; i < strEdge.length; i++) {
                String[] nodePlusEdge = arrListSelectedSNP4Network.get(i).toString().split("\t");

                // -- get the node --
                if (!tmNode.containsKey(nodePlusEdge[0])) { //for snp1
                    tmNode.put(nodePlusEdge[0], value++);
                }
                if (!tmNode.containsKey(nodePlusEdge[1])) { //for snp2
                    tmNode.put(nodePlusEdge[1], value++);
                }

                //-- get the edges --
                //add the edge information to an array
                strEdge[i] = "<edge " + "id=\"" + "e" + (i + 1) + "\"" + " source=\"" + tmNode.get(nodePlusEdge[0]) + "\" target=\"" + tmNode.get(nodePlusEdge[1]) + "\">\n" + "\t<data key=\"score\">" + nodePlusEdge[2] + "</data>\n" + "</edge>\n";

            }//end of for loop

            //save the information to a xml file
            toXml(tmNode, strEdge, xmlFilename);

            // -- 2nd step: build the network based on the xml file --
            drawNetworkImage(arrListSelectedSNP4Network);

            //empty the array list
            arrListSelectedSNP4Network.clear();

        }//end else
    }//end of showNetWork()

    /**
     * this methods draw and show the Network by the data from the xml file
     */
    private void drawNetworkImage(ArrayList arrListSelectedSNP4Network) {
        //try to show the image on other window.
        UILib.setPlatformLookAndFeel();
        String imageName = finalInputFile + "." + arrListSelectedSNP4Network.size() + "SNPs.jpg";
        JComponent graphview = new DrawImage(imageName).drawPic(xmlFilename, "name");

        // -- build a seporate frame for the network show --
        JFrame f = new JFrame();
        f.setTitle("The Network Built by the selcted item");
        f.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        f.setSize(800, 400);
        f.setLocationRelativeTo(null);
        f.getContentPane().setLayout(new BorderLayout());
        JScrollPane p = new JScrollPane(graphview);
        f.getContentPane().add(p);
        f.setVisible(true);
    }

    /**
     * 
     * @param map   contains the node information
     * @param edge  contains the edge information
     * @param xmlFileName   the name of the xml file will be written
     */
    private void toXml(TreeMap map, String[] edge, String xmlFileName) {
        try {
            FileWriter fw = new FileWriter(xmlFileName);
            BufferedWriter writer = new BufferedWriter(fw);

            //the head of the xml file
            writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + " <!--  An excerpt of an egocentric social network  -->\n" + " <graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\">\n" + " <graph edgedefault=\"undirected\">\n" + " \n <!-- data schema -->\n" + " <key id=\"name\"  for=\"node\" attr.name=\"name\" attr.type=\"string\"/>\n" + " <key id=\"score\" for=\"edge\" attr.name=\"score\" attr.type=\"string\"/>\n" + "\n <!-- nodes --> \n");

            //the node of the xml file
            Iterator iter = map.keySet().iterator();
            Object key = null;
            Object value = null;
            while (iter.hasNext()) {
                key = iter.next();
                value = map.get(key);
                writer.write("<node id=\"" + value.toString() + "\">\n" + "\t<data key=\"name\">" + key.toString() + "</data>\n" + "</node>\n");
            }
            key = null;
            value = null;
            iter = null;

            //the edge of the xml file
            writer.write("\n <!-- edges --> \n");
            for (int i = 0; i < edge.length; i++) {
                writer.write(edge[i]);
            }
            //the end of the xml file
            writer.write("\n</graph>\n</graphml>");
            writer.close();
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }//end of toXml()

    /**
     * to solve a java bug for JFileChooser
     * @return  a JFileChooser
     */
    public JFileChooser createJFileChooser() {
        class JF extends JFileChooser {

            public JF(String name) {
                super(name);
            }

            protected void setUI(ComponentUI newUI) {
                try {
                    super.setUI(newUI);
                } catch (NullPointerException e) {
                    if (newUI.getClass().getName().equals("com.sun.java.swing.plaf.windows.WindowsFileChooserUI")) {
                        try {
                            super.setUI(null);
                        } catch (NullPointerException ee) {
                            ui = null;
                        }
                        super.setUI(new MetalFileChooserUI(this));
                    } else {
                        throw e;
                    }
                }
            }
        }
        return new JF(".");
    }//end of filechooser

    /**
     *
     * @param str   the string to be checked
     * @param strA  the array
     * @return  true if string is in the array, false if not
     */
    private boolean isMember(String str, String[] strA) {
        for (String string : strA) {
            if (string.compareToIgnoreCase(str) == 0) {
                return true;
            }
        }
        return false;
    }//end of isMember()

    /**
     *
     * @param strArray  the array to be removed or remained
     * @param jtable    the target table
     * @param flag      true then remove the array from the ,
     *                  false then remain the array only
     */
    private void removeSnpFromRemainCorrelationTable(String[] strArray, JTable jtable, boolean flag) {
        //**************************************************************
        // remove the rows from the remaining table based on the filter file
        //**************************************************************
        int tableRowSize = jtable.getRowCount();
        Vector vecSnp = new Vector(tableRowSize); //for snp name

        //************  step 1: find the remaining variable *****************
//            String[] remainNameList = strAllfile.split("\n");

        //************  step 2: find the variable in the table ************

        //initialize the vecSnp
        for (int i = 0; i < tableRowSize; i++) {
            vecSnp.add(jtable.getValueAt(i, RemainCorrelationTableModel.SNP_INDEX));
        }

        //************  step 3: remove the row  ************
        for (int i = 0; i < tableRowSize; i++) { //outter for loop
            String strSnp = (String) vecSnp.elementAt(i);

            if (!flag) {
                if (!isMember(strSnp, strArray)) { //remove if not in the remain list
                    ((RemainCorrelationTableModel) jtable.getModel()).removeRow(i);
                    ((RemainCorrelationTableModel) jtable.getModel()).setRowCount(--tableRowSize);
                    jtable.revalidate();
                    vecSnp.removeElementAt(i);
                    i--;
                }
            } else {
                if (isMember(strSnp, strArray)) { //remove if in the remove list
                    ((DefaultTableModel) jtable.getModel()).removeRow(i);
                    ((DefaultTableModel) jtable.getModel()).setRowCount(--tableRowSize);
                    jtable.revalidate();
                    vecSnp.removeElementAt(i);
                    i--;
                }
            }
        }//end outter for loop
    }//end of removeSnpFromRemainCorrelationTable()

    /**
     *
     * @param jl    the label to be used to show the number
     * @param na    the number of attributes
     * @param ns    the number of samples
     */
    private void setNumberofAttrsAndSamples(JLabel jl, int na, int ns) {
        jl.setText("Number of Attributes is:    " + na + "       " + "Number of Samples is:      " + ns);
    }//end of setNumberofAttrsAndSamples()

    /**
     *  create jTableCorrelationsRemain by using the data from arrListRemain
     */
    private void createRemainingTable() {
        arrListRemain.clear();
        //-- get the snp names from the input file --
        myNetWork = new NetWork(new InformationTheoretica(finalInputFile), "init");
        arrListRemain = myNetWork.getSnpNames();
        setNumberofAttrsAndSamples(jLabelNumberOfAttrsAndSample,
                myNetWork.getNumbeOfAttributes(),
                myNetWork.getNumbeOfSamples());

        //---------------------------------------------------
        //show the remaining variables in the remaining table
        //---------------------------------------------------
        // -- create the volumn name vector --
        Vector remainTableColumnName = new Vector();
        remainTableColumnName.add("Selected");
        remainTableColumnName.add("SNP");
        // -- create the data vector --
        Vector vecRemainTableData = new Vector(arrListRemain.size());
        for (int i = 0; i < arrListRemain.size(); i++) {
            Vector temp = new Vector();
            temp.add(new Boolean(false));
            temp.add(arrListRemain.get(i));
            vecRemainTableData.add(temp);
        }
        // -- create the remain snp table
        jTableCorrelationsRemain.setModel(new RemainCorrelationTableModel(remainTableColumnName, vecRemainTableData));
        jTableCorrelationsRemain.setPreferredScrollableViewportSize(new Dimension(400, 90));
        jTableCorrelationsRemain.setCellSelectionEnabled(true);
        jTableCorrelationsRemain.revalidate();
        new SortManager(jTableCorrelationsRemain);
        jTableCorrelationsRemain.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
//                jTextFieldStatus.setText("remaining SNPs list changed " );
            }
        });
        vecRemoveNameList.clear();
        jTextAreaRemoveHistory.setText("");
    }//end of createRemainingTable()

    /**
     *  initial the variables defined by programmer, not IDE.
     */
    private void initUserDefinedVar() {
        inputFile = "example_input.tab"; //for input tab file
        inputAttrNameFile = "example_filter_list.txt"; //for input optional attribute name file
        finalInputFile = new String(); //for the final input file(after subArff)
        xmlFilename = "network.xml";// for the xml file name
//        interactionCutoff = 0.05; //for interaction information cutoff
//        filterCutoff = 0.8; //for filter cutoff
        myNetWork = new NetWork();//for network
        jProgressBarRun.setVisible(false);
        vecRemoveNameList = new Vector();
        myShowCorrTableModel = new CorrelationTableModel();
        myShowGainTableModel = new GainTableModel();
//        arrListSelectedSNP4Network = new ArrayList();
        jMenuFile.setMnemonic('F');
        jMenuRun.setMnemonic('U');
        jMenuExit.setMnemonic('E');
        jFileChooserMain = createJFileChooser();
        myOpenFileFilter = new OpenFileFilter();
        arrListRemain = new ArrayList();
        arrListRemainRemoveList = new ArrayList();
        correlationThreadCount = 0;
        networkThreadCount = 0;
        jEditorPaneHelpContent.addHyperlinkListener(new HyperlinkListener() {
            public void hyperlinkUpdate(HyperlinkEvent event) {
                if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    
//                    openURL(event.getURL().toString());
                    
                    //**************  below is java 6 version  **************
                    // ** if you want to use the java 6 version, comment the first statment
                    // ** in this if-block and uncomment the statements in the try-catch block

                    try {
                        java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
                        if (!java.awt.Desktop.isDesktopSupported()) {
                            JOptionPane.showMessageDialog(null, "Sorry, your Desktop is not supported (fatal)");
                        }else if (!desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {
                            JOptionPane.showMessageDialog(null, "Sorry, your Desktop doesn't support the browse action (fatal)");
                        }else{
                            desktop.browse(new java.net.URI(event.getURL().toString()));
                        }
                    } catch (Exception ioe) {
                         String str = "Sorry, java 6 is not installed.\n\nPlease copy the link and " +
                                 "paste to your browser address bar: \n\n" + event.getURL().toString();
                         JOptionPane.showMessageDialog(null, new JTextArea(str));
                    } 
                   
                }
            }
        });
    }

    private void openURL(String url) {
        final String errMsg = "Error attempting to launch web browser";
        String osName = System.getProperty("os.name");
        try {
            if (osName.startsWith("Mac OS")) {
                Class fileMgr = Class.forName("com.apple.eio.FileManager");
                Method openURL = fileMgr.getDeclaredMethod("openURL",
                        new Class[]{String.class});
                openURL.invoke(null, new Object[]{url});
            } else if (osName.startsWith("Windows")) {
                Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
            } else { //assume Unix or Linux
                String[] browsers = {
                    "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape"};
                String browser = null;
                for (int count = 0; count < browsers.length && browser == null; count++) {
                    if (Runtime.getRuntime().exec(
                            new String[]{"which", browsers[count]}).waitFor() == 0) {
                        browser = browsers[count];
                    }
                }
                if (browser == null) {
                    throw new Exception("Could not find web browser");
                } else {
                    Runtime.getRuntime().exec(new String[]{browser, url});
                }
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage());
        }
    }

    //*************************************************
    //   end of user defined methods
    //*************************************************
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GainGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonApply;
    private javax.swing.JButton jButtonBrowseFilterFile;
    private javax.swing.JButton jButtonBrowseInFile;
    private javax.swing.JButton jButtonGetCorrelations;
    private javax.swing.JButton jButtonRefresh;
    private javax.swing.JButton jButtonRemaingRemove;
    private javax.swing.JButton jButtonRevert;
    private javax.swing.JButton jButtonRunNetWork;
    private javax.swing.JButton jButtonRunPermutation;
    private javax.swing.JButton jButtonSaveCorrelationsRemainData;
    private javax.swing.JButton jButtonSaveCorrelationsTable;
    private javax.swing.JButton jButtonSaveGain;
    private javax.swing.JButton jButtonSaveMatrix;
    private javax.swing.JButton jButtonSaveNetworkDegreesTable;
    private javax.swing.JButton jButtonSavePermutationList;
    private javax.swing.JButton jButtonSaveSif;
    private javax.swing.JButton jButtonShowNetwork;
    private javax.swing.JButton jButtonTableRemove;
    private javax.swing.JCheckBox jCheckBoxShowFileInfo;
    private javax.swing.JEditorPane jEditorPaneHelpContent;
    private javax.swing.JLabel jLabePermutelLoopCount;
    private javax.swing.JLabel jLabelBrowse;
    private javax.swing.JLabel jLabelClock;
    private javax.swing.JLabel jLabelCutoff;
    private javax.swing.JLabel jLabelFalsePositiveRisk;
    private javax.swing.JLabel jLabelGUIname;
    private javax.swing.JLabel jLabelGain;
    private javax.swing.JLabel jLabelHelpTitle;
    private javax.swing.JLabel jLabelInterGainRangeSplit;
    private javax.swing.JLabel jLabelInteractionGainCutoff;
    private javax.swing.JLabel jLabelInteractionGainRange;
    private javax.swing.JLabel jLabelMatrix;
    private javax.swing.JLabel jLabelNumberOfAttrsAndSample;
    private javax.swing.JLabel jLabelOptionAttribute;
    private javax.swing.JLabel jLabelRun;
    private javax.swing.JLabel jLabelRunFilter;
    private javax.swing.JLabel jLabelSaveTableAsTab;
    private javax.swing.JLabel jLabelSif;
    private javax.swing.JLabel jLabelSymmetirc;
    private javax.swing.JMenuBar jMenuBarMain;
    private javax.swing.JMenu jMenuExit;
    private javax.swing.JMenu jMenuFile;
    private javax.swing.JMenuItem jMenuItemApply;
    private javax.swing.JMenuItem jMenuItemCalculate;
    private javax.swing.JMenuItem jMenuItemExit;
    private javax.swing.JMenuItem jMenuItemLoadAttrNameList;
    private javax.swing.JMenuItem jMenuItemLoadData;
    private javax.swing.JMenuItem jMenuItemRefreshTable;
    private javax.swing.JMenuItem jMenuItemRemoveFromCorrelatedTable;
    private javax.swing.JMenuItem jMenuItemRemoveFromRemainTable;
    private javax.swing.JMenuItem jMenuItemRevert;
    private javax.swing.JMenuItem jMenuItemRunNetwork;
    private javax.swing.JMenuItem jMenuItemSaveCorrelationd;
    private javax.swing.JMenuItem jMenuItemSaveGain;
    private javax.swing.JMenuItem jMenuItemSaveImage;
    private javax.swing.JMenuItem jMenuItemSaveMatrix;
    private javax.swing.JMenuItem jMenuItemSaveRemainingData;
    private javax.swing.JMenuItem jMenuItemSaveSif;
    private javax.swing.JMenuItem jMenuItemShowNetwork;
    private javax.swing.JMenu jMenuRun;
    private javax.swing.JPanel jPanelCorrelation;
    private javax.swing.JPanel jPanelCorrelationTable;
    private javax.swing.JPanel jPanelExampleFileShow;
    private javax.swing.JPanel jPanelHelp;
    private javax.swing.JPanel jPanelInteraction;
    private javax.swing.JPanel jPanelInteractionRefresh;
    private javax.swing.JPanel jPanelInteractionRefresh1;
    private javax.swing.JPanel jPanelInteractionRun;
    private javax.swing.JPanel jPanelInteractionSaveAs;
    private javax.swing.JPanel jPanelInteractionrResult;
    private javax.swing.JPanel jPanelLoadData;
    private javax.swing.JPanel jPanelNetworkDegrees;
    private javax.swing.JPanel jPanelOptionalAttribute;
    private javax.swing.JPanel jPanelPermutationControlPanel;
    private javax.swing.JPanel jPanelPermutationList;
    private javax.swing.JPanel jPanelPreprocess;
    private javax.swing.JPanel jPanelRandomPermutation;
    private javax.swing.JPanel jPanelRemainAttrs;
    private javax.swing.JPanel jPanelRemoveHistory;
    private javax.swing.JPanel jPanelStatus;
    private javax.swing.JProgressBar jProgressBarRun;
    private javax.swing.JScrollPane jScrollPaneCorrelationTable;
    private javax.swing.JScrollPane jScrollPaneExampleFileShow;
    private javax.swing.JScrollPane jScrollPaneHelpContent;
    private javax.swing.JScrollPane jScrollPaneInteractionResult;
    private javax.swing.JScrollPane jScrollPaneNetworkDegrees;
    private javax.swing.JScrollPane jScrollPanePermutationList;
    private javax.swing.JScrollPane jScrollPaneRemainAttrs;
    private javax.swing.JScrollPane jScrollPaneRemoveHistory;
    private javax.swing.JSeparator jSeparatorFile;
    private javax.swing.JSeparator jSeparatorNetwork;
    private javax.swing.JSeparator jSeparatorPermutationControlPanel;
    private javax.swing.JSeparator jSeparatorRun;
    private javax.swing.JTabbedPane jTabbedPaneInteractionResult;
    private javax.swing.JTabbedPane jTabbedPaneMain;
    private javax.swing.JTabbedPane jTabbedPanePermutation;
    private javax.swing.JTabbedPane jTabbedPaneResultWindow;
    private javax.swing.JTable jTableCorrelations;
    private javax.swing.JTable jTableCorrelationsRemain;
    private javax.swing.JTable jTableInteractionGainResult;
    private javax.swing.JTable jTableNetworkDegrees;
    private javax.swing.JTextArea jTextAreaExampleFileShow;
    private javax.swing.JTextArea jTextAreaPermutationList;
    private javax.swing.JTextArea jTextAreaRemoveHistory;
    private javax.swing.JTextField jTextFieldCutoff;
    private javax.swing.JTextField jTextFieldFalsePositiveRisk;
    private javax.swing.JTextField jTextFieldInteractionGainCutoff;
    private javax.swing.JTextField jTextFieldLoadData;
    private javax.swing.JTextField jTextFieldMaxRange;
    private javax.swing.JTextField jTextFieldMinRange;
    private javax.swing.JTextField jTextFieldOptionAttribute;
    private javax.swing.JTextField jTextFieldPermuteLoopCount;
    private javax.swing.JTextField jTextFieldStatus;
    private javax.swing.JTextField jTextFieldSymmetric;
    // End of variables declaration//GEN-END:variables
    //user defined variable declaration
    private String inputFile; //for input tab file
    private String xmlFilename; //for input tab file
    private String inputAttrNameFile; //for input optional attribute name file
    private String finalInputFile; //for the final input file(after subArff)
    private NetWork myNetWork; //for network building
    private Vector vecRemoveNameList;//for removed correlated name list
//    private ArrayList arrListSelectedSNP4Network;// for network show
    private CorrelationTableModel myShowCorrTableModel;// for correlations table
    private GainTableModel myShowGainTableModel;// for correlations table
    private JFileChooser jFileChooserMain; // for file chooser
    private OpenFileFilter myOpenFileFilter;
    private ArrayList arrListRemain;
    private ArrayList arrListRemainRemoveList;
    private int correlationThreadCount;
    private int networkThreadCount;
    //end of user defined variable declaration
}

/**
 * generate a fileFilter for the input file type
 * @author DTian
 */
class OpenFileFilter extends FileFilter {

    public boolean accept(File f) {
        return f.getName().toLowerCase().endsWith(".txt") || f.isDirectory() || f.getName().toLowerCase().endsWith(".tab") || f.getName().toLowerCase().endsWith(".arff");
    }

    public String getDescription() {
        return "Accepted Files";
    }
}

/**
 * this class is to generate a digital clock include year,month,day,
 * hour,minute,second
 * 
 * @author DTian
 */
class MyClock extends Thread {

    private JLabel clock;

    public MyClock(JLabel clock) {
        this.clock = clock;
    }

    /**
     * thread body, refresh every 1 second
     */
    public void run() {
        while (true) {
            clock.setText(this.getTime());
            clock.setHorizontalAlignment(JLabel.CENTER);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * get the current time and output it as a string
     * @return
     */
    public String getTime() {
        Calendar c = new GregorianCalendar();
        String time = c.get(Calendar.YEAR) + "-" +
                (c.get(Calendar.MONTH) + 1) + "-" +
                c.get(Calendar.DATE) + "  ";
        int h = c.get(Calendar.HOUR_OF_DAY);
        int m = c.get(Calendar.MINUTE);
        int s = c.get(Calendar.SECOND);
        String ph = h < 10 ? "0" : "";
        String pm = m < 10 ? "0" : "";
        String ps = s < 10 ? "0" : "";
        return time + ph + h + ":" + pm + m + ":" + ps + s;
    }
}
